Class: Cybertrain::Job::Run
- Inherits:
-
Object
- Object
- Cybertrain::Job::Run
- Defined in:
- cybertrain/job.rb
Overview
One claimed attempt of a job, as the block given to register receives it: the row’s id, kind and payload, the attempt number (1 for the first; the claim counted it), and the claim’s label, which with the attempt number fences the outcome write. A policy hands it to retry_later or discard, which write the outcome and mark it written, so the worker writes nothing more for it.
Instance Attribute Summary collapse
-
#run_attempts ⇒ Integer
readonly
This attempt’s number, 1 for the first.
-
#run_claimed_by ⇒ String
readonly
The claiming process’s process_label.
-
#run_id ⇒ Integer
readonly
The job’s id.
-
#run_kind ⇒ String
readonly
The kind the job was enqueued under.
-
#run_now ⇒ Integer
readonly
The epoch seconds the attempt was claimed at (the
nowof work_one); its outcome writes are timed from it. -
#run_payload ⇒ String
readonly
The payload given to enqueue, as it is.
-
#run_request_id ⇒ String
readonly
The id of the request the job was enqueued in (recorded in the row’s
request_id), or, for a job enqueued by another job, the request id that job carries; “” when it was enqueued outside both (a scheduled task, a feed, a command); the job’s log lines carry it.
Instance Method Summary collapse
-
#initialize(run_id, run_kind, run_payload, run_attempts, run_claimed_by, run_now, run_request_id = "") ⇒ Run
constructor
A new instance of Run.
-
#run_args ⇒ Hash{String => Object}
The payload parsed as a JSON object, computed once.
-
#run_outcome_written! ⇒ nil
Marks the outcome written: the worker then writes nothing for this attempt when the block returns or raises.
-
#run_outcome_written? ⇒ Boolean
True once retry_later or discard wrote, or tried to write, this attempt’s outcome.
Constructor Details
#initialize(run_id, run_kind, run_payload, run_attempts, run_claimed_by, run_now, run_request_id = "") ⇒ Run
Returns a new instance of Run.
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'cybertrain/job.rb', line 133 def initialize(run_id, run_kind, run_payload, run_attempts, run_claimed_by, run_now, run_request_id = "") @run_id = run_id @run_kind = run_kind @run_payload = run_payload @run_attempts = run_attempts @run_claimed_by = run_claimed_by @run_now = run_now @run_request_id = run_request_id @run_args = Cast.empty_hash @run_args_parsed = false @run_written = false end |
Instance Attribute Details
#run_attempts ⇒ Integer (readonly)
Returns this attempt’s number, 1 for the first.
109 110 111 |
# File 'cybertrain/job.rb', line 109 def run_attempts @run_attempts end |
#run_claimed_by ⇒ String (readonly)
Returns the claiming process’s Cybertrain::Job.process_label.
112 113 114 |
# File 'cybertrain/job.rb', line 112 def run_claimed_by @run_claimed_by end |
#run_id ⇒ Integer (readonly)
Returns the job’s id.
100 101 102 |
# File 'cybertrain/job.rb', line 100 def run_id @run_id end |
#run_kind ⇒ String (readonly)
Returns the kind the job was enqueued under.
103 104 105 |
# File 'cybertrain/job.rb', line 103 def run_kind @run_kind end |
#run_now ⇒ Integer (readonly)
Returns the epoch seconds the attempt was claimed at (the
now of Cybertrain::Job.work_one); its outcome writes are timed from it.
116 117 118 |
# File 'cybertrain/job.rb', line 116 def run_now @run_now end |
#run_payload ⇒ String (readonly)
Returns the payload given to Cybertrain::Job.enqueue, as it is.
106 107 108 |
# File 'cybertrain/job.rb', line 106 def run_payload @run_payload end |
#run_request_id ⇒ String (readonly)
Returns the id of the request the job was enqueued in
(recorded in the row’s request_id), or, for a job enqueued by
another job, the request id that job carries; “” when it was
enqueued outside both (a scheduled task, a feed, a command); the
job’s log lines carry it.
123 124 125 |
# File 'cybertrain/job.rb', line 123 def run_request_id @run_request_id end |
Instance Method Details
#run_args ⇒ Hash{String => Object}
The payload parsed as a JSON object, computed once. A payload that is not a JSON object (plain text, an Array, invalid JSON, “”) gives an empty Hash; it never raises.
151 152 153 154 155 156 157 |
# File 'cybertrain/job.rb', line 151 def run_args unless @run_args_parsed @run_args = Cast.json_hash(@run_payload) @run_args_parsed = true end @run_args end |
#run_outcome_written! ⇒ nil
Marks the outcome written: the worker then writes nothing for this attempt when the block returns or raises.
170 171 172 173 |
# File 'cybertrain/job.rb', line 170 def run_outcome_written! @run_written = true nil end |
#run_outcome_written? ⇒ Boolean
Returns true once Cybertrain::Job.retry_later or Cybertrain::Job.discard wrote, or tried to write, this attempt’s outcome.
162 163 164 |
# File 'cybertrain/job.rb', line 162 def run_outcome_written? @run_written end |