Class: Zizq::Resources::Job
- Defined in:
- lib/zizq/resources/job.rb
Overview
Typed wrapper around a job response hash.
Exposes named accessor methods with Ruby-idiomatic types (fractional seconds instead of milliseconds) and link methods that follow related resources through the Client.
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#attempts ⇒ Object
: () -> Integer.
-
#backoff ⇒ Object
Backoff configuration converted from the wire format (ms) to the Ruby-idiomatic format (seconds), matching the Zizq::backoff type.
-
#complete! ⇒ Object
Mark this job as successfully completed.
-
#completed_at ⇒ Object
: () -> Float?.
-
#delete ⇒ Object
Delete this job.
-
#dequeued_at ⇒ Object
: () -> Float?.
-
#duplicate? ⇒ Boolean
: () -> bool.
-
#errors(order: nil, limit: nil, page_size: nil) ⇒ Object
Fetch the error history for this job.
-
#fail!(message:, error_type: nil, backtrace: nil, retry_at: nil, kill: false) ⇒ Object
Report this job as failed.
-
#failed_at ⇒ Object
: () -> Float?.
-
#id ⇒ Object
: () -> String.
-
#payload ⇒ Object
: () -> Hash[String, untyped]?.
-
#priority ⇒ Object
: () -> Integer.
-
#queue ⇒ Object
: () -> String.
-
#ready_at ⇒ Object
: () -> Float?.
-
#retention ⇒ Object
Retention configuration converted from the wire format (ms) to the Ruby-idiomatic format (seconds), matching the Zizq::retention type.
-
#retry_limit ⇒ Object
: () -> Integer?.
-
#status ⇒ Object
: () -> String.
-
#type ⇒ Object
: () -> String.
-
#unique_key ⇒ Object
: () -> String?.
-
#unique_while ⇒ Object
: () -> Zizq::unique_scope?.
-
#update(queue: Zizq::UNCHANGED, priority: Zizq::UNCHANGED, ready_at: Zizq::UNCHANGED, retry_limit: Zizq::UNCHANGED, backoff: Zizq::UNCHANGED, retention: Zizq::UNCHANGED) ⇒ Object
Update this job’s mutable fields.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Zizq::Resources::Resource
Instance Method Details
#attempts ⇒ Object
: () -> Integer
21 |
# File 'lib/zizq/resources/job.rb', line 21 def attempts = @data["attempts"] #: () -> Integer |
#backoff ⇒ Object
Backoff configuration converted from the wire format (ms) to the Ruby-idiomatic format (seconds), matching the Zizq::backoff type.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zizq/resources/job.rb', line 33 def backoff #: () -> Zizq::backoff? raw = @data["backoff"] return nil unless raw { exponent: raw["exponent"].to_f, base: raw["base_ms"] / 1000.0, jitter: raw["jitter_ms"] / 1000.0 } end |
#complete! ⇒ Object
Mark this job as successfully completed.
67 68 69 |
# File 'lib/zizq/resources/job.rb', line 67 def complete! #: () -> nil @client.report_success(id) end |
#completed_at ⇒ Object
: () -> Float?
25 |
# File 'lib/zizq/resources/job.rb', line 25 def completed_at = ms_to_seconds(@data["completed_at"]) #: () -> Float? |
#delete ⇒ Object
Delete this job.
86 87 88 |
# File 'lib/zizq/resources/job.rb', line 86 def delete @client.delete_job(id) end |
#dequeued_at ⇒ Object
: () -> Float?
23 |
# File 'lib/zizq/resources/job.rb', line 23 def dequeued_at = ms_to_seconds(@data["dequeued_at"]) #: () -> Float? |
#duplicate? ⇒ Boolean
: () -> bool
29 |
# File 'lib/zizq/resources/job.rb', line 29 def duplicate? = @data["duplicate"] == true #: () -> bool |
#errors(order: nil, limit: nil, page_size: nil) ⇒ Object
Fetch the error history for this job.
62 63 64 |
# File 'lib/zizq/resources/job.rb', line 62 def errors(order: nil, limit: nil, page_size: nil) ErrorEnumerator.new(id, order:, limit:, page_size:) end |
#fail!(message:, error_type: nil, backtrace: nil, retry_at: nil, kill: false) ⇒ Object
Report this job as failed.
79 80 81 |
# File 'lib/zizq/resources/job.rb', line 79 def fail!(message:, error_type: nil, backtrace: nil, retry_at: nil, kill: false) @client.report_failure(id, message:, error_type:, backtrace:, retry_at:, kill:) end |
#failed_at ⇒ Object
: () -> Float?
24 |
# File 'lib/zizq/resources/job.rb', line 24 def failed_at = ms_to_seconds(@data["failed_at"]) #: () -> Float? |
#id ⇒ Object
: () -> String
15 |
# File 'lib/zizq/resources/job.rb', line 15 def id = @data["id"] #: () -> String |
#payload ⇒ Object
: () -> Hash[String, untyped]?
22 |
# File 'lib/zizq/resources/job.rb', line 22 def payload = @data["payload"] #: () -> Hash[String, untyped]? |
#priority ⇒ Object
: () -> Integer
18 |
# File 'lib/zizq/resources/job.rb', line 18 def priority = @data["priority"] #: () -> Integer |
#queue ⇒ Object
: () -> String
17 |
# File 'lib/zizq/resources/job.rb', line 17 def queue = @data["queue"] #: () -> String |
#ready_at ⇒ Object
: () -> Float?
20 |
# File 'lib/zizq/resources/job.rb', line 20 def ready_at = ms_to_seconds(@data["ready_at"]) #: () -> Float? |
#retention ⇒ Object
Retention configuration converted from the wire format (ms) to the Ruby-idiomatic format (seconds), matching the Zizq::retention type.
46 47 48 49 50 51 52 53 54 |
# File 'lib/zizq/resources/job.rb', line 46 def retention #: () -> Zizq::retention? raw = @data["retention"] return nil unless raw result = {} #: Hash[Symbol, Float] result[:completed] = raw["completed_ms"] / 1000.0 if raw["completed_ms"] result[:dead] = raw["dead_ms"] / 1000.0 if raw["dead_ms"] result end |
#retry_limit ⇒ Object
: () -> Integer?
26 |
# File 'lib/zizq/resources/job.rb', line 26 def retry_limit = @data["retry_limit"] #: () -> Integer? |
#status ⇒ Object
: () -> String
19 |
# File 'lib/zizq/resources/job.rb', line 19 def status = @data["status"] #: () -> String |
#type ⇒ Object
: () -> String
16 |
# File 'lib/zizq/resources/job.rb', line 16 def type = @data["type"] #: () -> String |
#unique_key ⇒ Object
: () -> String?
27 |
# File 'lib/zizq/resources/job.rb', line 27 def unique_key = @data["unique_key"] #: () -> String? |
#unique_while ⇒ Object
: () -> Zizq::unique_scope?
28 |
# File 'lib/zizq/resources/job.rb', line 28 def unique_while = @data["unique_while"]&.to_sym #: () -> Zizq::unique_scope? |
#update(queue: Zizq::UNCHANGED, priority: Zizq::UNCHANGED, ready_at: Zizq::UNCHANGED, retry_limit: Zizq::UNCHANGED, backoff: Zizq::UNCHANGED, retention: Zizq::UNCHANGED) ⇒ Object
Update this job’s mutable fields.
Returns the updated job.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/zizq/resources/job.rb', line 101 def update(queue: Zizq::UNCHANGED, priority: Zizq::UNCHANGED, ready_at: Zizq::UNCHANGED, retry_limit: Zizq::UNCHANGED, backoff: Zizq::UNCHANGED, retention: Zizq::UNCHANGED) job = @client.update_job( id, queue:, priority:, ready_at:, retry_limit:, backoff:, retention: ) # Make sure this job's fields are updated. @data.merge!(job.to_h) job end |