This is where the work of a job shall be. Returns a result code (0 if run without errors, !=0 otherwise) Everything thrown through the error channel will be captured The property :result_output can be set to the desired output log
# File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/jobs/job_utils.rb, line 77
77: def do_job_work
78: raise NotImplementedError.new("Implement do_job_work() in your Job subclass")
79: end
This is the function used to fire the job work.
# File vendor/plugins/ubiquo_jobs/lib/ubiquo_jobs/jobs/job_utils.rb, line 27
27: def run!
28: # Check initial prerequisites
29: unless state == STATES[:instantiated] && runner
30: raise "Object not correctly instantiated! Use ActiveManager.get to get a job"
31: end
32:
33: # Initial marking
34: set_property :started_at, Time.now.utc
35: set_property :tries, self.tries + 1
36: set_property :state, STATES[:started]
37:
38: # Manage error channel to capture errors
39: orig_stderr = STDERR.dup
40: new_stderr = Tempfile.new('stderr')
41: STDERR.reopen(new_stderr)
42:
43: # Call to do the real job work
44: result = begin
45: do_job_work
46: rescue => e
47: # log the caught exception
48: exception_error = e.inspect
49: # return an error result code
50: -1
51: end
52:
53: # Update state accordingly to the result
54: new_state = if result != 0
55: tries >= 3 ? STATES[:error] : STATES[:waiting]
56: else
57: notify_finished
58: STATES[:finished]
59: end
60:
61: error_log = exception_error || (IO.read(new_stderr.path) rescue "Can't read error log")
62:
63: # Final properties update
64: set_property :ended_at, Time.now.utc
65: set_property :state, new_state
66: set_property :result_code, result
67: set_property :result_error, error_log
68:
69: # Reset to the original error out
70: STDERR.reopen(orig_stderr)
71: new_stderr.close!
72: end
Disabled; run with $DEBUG to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.