Class: BatchKit::Job::Run
- Defined in:
- lib/batch-kit/framework/job_run.rb
Overview
Captures details of an execution of a job.
Constant Summary collapse
- PROPERTIES =
[ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ]
Instance Attribute Summary collapse
-
#:cmd_line(: cmd_line) ⇒ Object
readonly
The command-line used to invoke the job.
-
#:job_args(: job_args) ⇒ Object
readonly
A structure holding the parsed job arguments.
-
#:requestors(: requestors) ⇒ Object
readonly
A list of the requestor(s) that requested for this job to be run.
-
#:run_by(: run_by) ⇒ Object
readonly
The name of the user that ran this job instance.
-
#:task_runs(: task_runs) ⇒ Object
readonly
An array containing details of the tasks that were executed by this job.
Attributes inherited from Runnable
#definition, #end_time, #exception, #exit_code, #instance, #lock_name, #lock_timeout, #lock_wait_timeout, #object, #start_time, #status
Instance Method Summary collapse
-
#:end_time=(: end_time=(value)) ⇒ Object
Time at which the job ended execution.
-
#:exception=(: exception=(value)) ⇒ Object
Any uncaught exception that occurred during job execution (and which was not caught by a task run).
-
#:exit_code=(: exit_code=(value)) ⇒ Object
An exit status code for the job, where 0 signifies success, and non-zero failure.
-
#:job_run_id=(: job_run_id=(value)) ⇒ Object
An integer identifier that uniquely identifies this job run.
-
#:pid=(: pid=(value)) ⇒ Object
A process identifier (PID) for the process that is running the job.
-
#:request_id=(: request_id=(value)) ⇒ Object
An integer identifier that links this job run to a job run request (if job is run on-demand).
-
#:start_time=(: start_time=(value)) ⇒ Object
Time at which the job started executing.
-
#<<(task_run) ⇒ Object
Adds a Task::Run to this Job::Run.
-
#abort(process_obj) ⇒ Object
Called if a batch process is aborted.
-
#around_execute(process_obj, *args) { ... } ⇒ Object
Called as the process is executing.
-
#failure(process_obj, exception) ⇒ Object
Called after the process executes and fails.
-
#initialize(job_def, job_object, *run_args) ⇒ Run
constructor
Instantiate a new JobRun representing a run of a job.
-
#persist? ⇒ Boolean
True if the job run should be recorded via any persistence layer.
-
#success(process_obj, result) ⇒ Object
Called after the process executes and completes successfully.
-
#to_s ⇒ String
A short representation of this job run.
Methods inherited from Runnable
add_delegated_properties, #elapsed, #event_name, #label, #post_execute, #pre_execute
Methods included from Lockable
Constructor Details
#initialize(job_def, job_object, *run_args) ⇒ Run
Instantiate a new JobRun representing a run of a job.
59 60 61 62 63 64 65 66 67 |
# File 'lib/batch-kit/framework/job_run.rb', line 59 def initialize(job_def, job_object, *run_args) raise ArgumentError unless job_def.is_a?(Job::Definition) @run_by = Etc.getlogin @cmd_line = "#{$0} #{ARGV.map{ |s| s =~ / |^\*$/ ? %Q{"#{s}"} : s }.join(' ')}".strip @pid = ::Process.pid @task_runs = [] @job_args = job_object.arguments if job_object.respond_to?(:arguments) super(job_def, job_object, run_args) end |
Instance Attribute Details
#:cmd_line(: cmd_line) ⇒ Object (readonly)
The command-line used to invoke the job.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:job_args(: job_args) ⇒ Object (readonly)
A structure holding the parsed job arguments.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:requestors(: requestors) ⇒ Object (readonly)
A list of the requestor(s) that requested for this job to be run. May be more than one if the request has been in a queue.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:run_by(: run_by) ⇒ Object (readonly)
The name of the user that ran this job instance.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:task_runs(: task_runs) ⇒ Object (readonly)
An array containing details of the tasks that were executed by this job.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
Instance Method Details
#:end_time=(: end_time=(value)) ⇒ Object
Time at which the job ended execution.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:exception=(: exception=(value)) ⇒ Object
Any uncaught exception that occurred during job execution (and which was not caught by a task run).
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:exit_code=(: exit_code=(value)) ⇒ Object
An exit status code for the job, where 0 signifies success, and non-zero failure. A value of -1 indicates the job was aborted (killed).
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:job_run_id=(: job_run_id=(value)) ⇒ Object
An integer identifier that uniquely identifies this job run.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:pid=(: pid=(value)) ⇒ Object
A process identifier (PID) for the process that is running the job.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:request_id=(: request_id=(value)) ⇒ Object
An integer identifier that links this job run to a job run request (if job is run on-demand).
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#:start_time=(: start_time=(value)) ⇒ Object
Time at which the job started executing.
37 38 39 40 41 |
# File 'lib/batch-kit/framework/job_run.rb', line 37 PROPERTIES = [ :run_by, :pid, :job_run_id, :cmd_line, :job_args, :request_id, :requestors, :task_runs ] |
#<<(task_run) ⇒ Object
Adds a Task::Run to this Job::Run.
71 72 73 74 75 76 |
# File 'lib/batch-kit/framework/job_run.rb', line 71 def <<(task_run) unless task_run.is_a?(Task::Run) raise ArgumentError, "Only Task::Run objects can be added to this Job::Run" end @task_runs << task_run end |
#abort(process_obj) ⇒ Object
Called if a batch process is aborted.
122 123 124 125 |
# File 'lib/batch-kit/framework/job_run.rb', line 122 def abort(process_obj) super process_obj.on_abort if process_obj.respond_to?(:on_abort) end |
#around_execute(process_obj, *args) { ... } ⇒ Object
Called as the process is executing.
86 87 88 89 90 91 92 |
# File 'lib/batch-kit/framework/job_run.rb', line 86 def around_execute(process_obj, *args) if process_obj.job_run && process_obj.job_run.status == :executing raise "There is already a job run active (#{process_obj.job_run}) for #{process_obj}" end process_obj.instance_variable_set(:@__job_run__, self) super end |
#failure(process_obj, exception) ⇒ Object
Called after the process executes and fails.
112 113 114 115 |
# File 'lib/batch-kit/framework/job_run.rb', line 112 def failure(process_obj, exception) super process_obj.on_failure(exception) if process_obj.respond_to?(:on_failure) end |
#persist? ⇒ Boolean
Returns True if the job run should be recorded via any persistence layer.
130 131 132 |
# File 'lib/batch-kit/framework/job_run.rb', line 130 def persist? !definition.do_not_track end |
#success(process_obj, result) ⇒ Object
Called after the process executes and completes successfully.
100 101 102 103 |
# File 'lib/batch-kit/framework/job_run.rb', line 100 def success(process_obj, result) super process_obj.on_success if process_obj.respond_to?(:on_success) end |
#to_s ⇒ String
Returns a short representation of this job run.
136 137 138 |
# File 'lib/batch-kit/framework/job_run.rb', line 136 def to_s "<BatchKit::Job::Run label='#{label}'>" end |