Class: Wurk::Status::Record
- Inherits:
-
Object
- Object
- Wurk::Status::Record
- Defined in:
- lib/wurk/status/record.rb
Overview
Read-only view of one status:<jid> HASH. Redis hands back strings for
everything; this is where they become the types a caller expects, so no
consumer (dashboard, HTTP API, a chain deciding what to pipe onward) has
to know the row is stringly-typed on the wire.
A field the writer never set reads as nil rather than 0 or '' — "this job reported no progress" and "this job is at 0" are different answers.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#jid ⇒ Object
readonly
Returns the value of attribute jid.
Instance Method Summary collapse
-
#[](field) ⇒ Object
Raw field access for anything without a reader.
- #attempt ⇒ Object
- #enqueued_at ⇒ Object
- #error_class ⇒ Object
- #error_message ⇒ Object
- #finished_at ⇒ Object
-
#initialize(jid, data) ⇒ Record
constructor
A new instance of Record.
-
#job_class ⇒ Object
classis the wire field name — it matches the job hash — but it is not a legal reader name. - #message ⇒ Object
- #progress ⇒ Object
- #queue ⇒ Object
-
#result ⇒ Object
The stored return value of
perform, decoded. -
#result_truncated? ⇒ Boolean
True when the return value was bigger than Middleware::Status::MAX_RESULT_BYTES and only its head was kept.
-
#result_withheld? ⇒ Boolean
True when the job's class set
encrypt: true, so its return value was deliberately never stored — see Middleware::Status#withhold_result?. - #started_at ⇒ Object
- #state ⇒ Object
-
#to_h ⇒ Object
Wire field names, not reader names: this hash is what the dashboard and the HTTP API serve, and
classis the name every other Wurk JSON surface uses for a job's class. - #total ⇒ Object
Constructor Details
#initialize(jid, data) ⇒ Record
Returns a new instance of Record.
17 18 19 20 |
# File 'lib/wurk/status/record.rb', line 17 def initialize(jid, data) @jid = jid @data = data.freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/wurk/status/record.rb', line 15 def data @data end |
#jid ⇒ Object (readonly)
Returns the value of attribute jid.
15 16 17 |
# File 'lib/wurk/status/record.rb', line 15 def jid @jid end |
Instance Method Details
#[](field) ⇒ Object
Raw field access for anything without a reader.
67 |
# File 'lib/wurk/status/record.rb', line 67 def [](field) = @data[field.to_s] |
#attempt ⇒ Object
34 |
# File 'lib/wurk/status/record.rb', line 34 def attempt = @data['attempt']&.to_i |
#enqueued_at ⇒ Object
36 |
# File 'lib/wurk/status/record.rb', line 36 def enqueued_at = @data['enqueued_at']&.to_f |
#error_class ⇒ Object
25 |
# File 'lib/wurk/status/record.rb', line 25 def error_class = @data['error_class'] |
#error_message ⇒ Object
26 |
# File 'lib/wurk/status/record.rb', line 26 def = @data['error_message'] |
#finished_at ⇒ Object
38 |
# File 'lib/wurk/status/record.rb', line 38 def finished_at = @data['finished_at']&.to_f |
#job_class ⇒ Object
class is the wire field name — it matches the job hash — but it is
not a legal reader name.
30 |
# File 'lib/wurk/status/record.rb', line 30 def job_class = @data['class'] |
#message ⇒ Object
24 |
# File 'lib/wurk/status/record.rb', line 24 def = @data['message'] |
#progress ⇒ Object
32 |
# File 'lib/wurk/status/record.rb', line 32 def progress = @data['progress']&.to_i |
#queue ⇒ Object
23 |
# File 'lib/wurk/status/record.rb', line 23 def queue = @data['queue'] |
#result ⇒ Object
The stored return value of perform, decoded. JSON only — see
CLAUDE.md; a result that wouldn't serialize never reached Redis.
A truncated result is a JSON fragment, so there is nothing to decode: it comes back as the raw head string, which is still the most useful thing anyone can be handed — the alternative is nothing at all.
58 59 60 61 62 63 64 |
# File 'lib/wurk/status/record.rb', line 58 def result raw = @data['result'] return nil if raw.nil? return raw if result_truncated? ::JSON.parse(raw) end |
#result_truncated? ⇒ Boolean
True when the return value was bigger than Middleware::Status::MAX_RESULT_BYTES and only its head was kept. Check this before treating #result as data.
43 |
# File 'lib/wurk/status/record.rb', line 43 def result_truncated? = @data['result_truncated'] == '1' |
#result_withheld? ⇒ Boolean
True when the job's class set encrypt: true, so its return value was
deliberately never stored — see
Middleware::Status#withhold_result?. Separates "the job returned
nothing" from "the job returned something Wurk refused to keep beside
the encrypted args in plaintext".
50 |
# File 'lib/wurk/status/record.rb', line 50 def result_withheld? = @data['result_withheld'] == '1' |
#started_at ⇒ Object
37 |
# File 'lib/wurk/status/record.rb', line 37 def started_at = @data['started_at']&.to_f |
#state ⇒ Object
22 |
# File 'lib/wurk/status/record.rb', line 22 def state = @data['state'] |
#to_h ⇒ Object
Wire field names, not reader names: this hash is what the dashboard and
the HTTP API serve, and class is the name every other Wurk JSON
surface uses for a job's class.
72 73 74 75 76 77 78 |
# File 'lib/wurk/status/record.rb', line 72 def to_h { 'jid' => jid, 'state' => state, 'queue' => queue, 'class' => job_class, 'enqueued_at' => enqueued_at, 'started_at' => started_at, 'finished_at' => finished_at, 'progress' => progress, 'total' => total, 'message' => , 'result' => result, 'result_truncated' => result_truncated?, 'result_withheld' => result_withheld?, 'error_class' => error_class, 'error_message' => , 'attempt' => attempt } end |
#total ⇒ Object
33 |
# File 'lib/wurk/status/record.rb', line 33 def total = @data['total']&.to_i |