Class: Chutzen::Job
Overview
Holds a description for a job and executes it.
Instance Method Summary collapse
-
#each ⇒ Object
Yields Command instances for each command in the description.
-
#initialize(description) ⇒ Job
constructor
A new instance of Job.
-
#perform ⇒ Object
Perform all commands in the job.
- #properties ⇒ Object
Constructor Details
#initialize(description) ⇒ Job
Returns a new instance of Job.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/chutzen/job.rb', line 10 def initialize(description) @notify = nil @result = {} description.each do |name, value| instance_variable_set("@#{name}", value) end @uuid = SecureRandom.uuid @work_path = File.join(ENV['HOME'], 'chutzen', @uuid) @dictionary = Dictionary.new(properties) end |
Instance Method Details
#each ⇒ Object
Yields Command instances for each command in the description.
32 33 34 35 36 37 38 39 40 |
# File 'lib/chutzen/job.rb', line 32 def each @commands.each do |description| yield Command.new( description, dictionary: @dictionary, work_path: @work_path ) end end |
#perform ⇒ Object
Perform all commands in the job.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chutzen/job.rb', line 43 def perform FileUtils.mkdir_p(@work_path) map do |command| perform_notification(command.perform) command end rescue Chutzen::StandardError => e warn("Job failed: #{e}") perform_exception_notification(e) ensure FileUtils.rm_rf(@work_path) end |