Class: Penelope::Core::Job
- Inherits:
-
Object
- Object
- Penelope::Core::Job
- Includes:
- DataMapper::Resource
- Defined in:
- lib/penelope/core/job.rb
Direct Known Subclasses
Instance Method Summary collapse
- #cleanup ⇒ Object
- #perform ⇒ Object
- #prepare ⇒ Object
- #report ⇒ Object
- #retrieve ⇒ Object
- #run ⇒ Object
- #working_directory ⇒ Object
Instance Method Details
#cleanup ⇒ Object
16 17 18 19 |
# File 'lib/penelope/core/job.rb', line 16 def cleanup # TODO archive working directory FileUtils.rm_rf working_directory end |
#perform ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/penelope/core/job.rb', line 21 def perform @start_time = Time.now begin prepare retrieve run rescue Exception => e @exceptions ||= [] @exceptions << e. end @end_time = Time.now report cleanup end |
#prepare ⇒ Object
36 37 38 |
# File 'lib/penelope/core/job.rb', line 36 def prepare FileUtils.mkdir_p working_directory end |
#report ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/penelope/core/job.rb', line 62 def report jr = JobReport.new( pid: @pid, exit_status: @exit_status, start_time: @start_time, end_time: @end_time, result: @result, job_id: id ) jr.exceptions = @exceptions.to_yaml if @exceptions jr.save end |
#retrieve ⇒ Object
40 41 42 |
# File 'lib/penelope/core/job.rb', line 40 def retrieve raise 'Not Implemented' end |
#run ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/penelope/core/job.rb', line 44 def run @exceptions = nil # TODO wrap in Docker container begin FileUtils.cd(working_directory) do @result = IO.popen(entry_point).read end @exit_status = $?.exitstatus @pid = $?.pid rescue Exception => e @exit_status ||= -1 @pid ||= -1 @exceptions ||= [] @exceptions << e. end @ran = true end |
#working_directory ⇒ Object
75 76 77 |
# File 'lib/penelope/core/job.rb', line 75 def working_directory File.join(CONFIG[:data][:directory], self.class.name, id.to_s) end |