Class: Zizq::Resources::Job
- Inherits:
-
JobTemplate
- Object
- Resource
- JobTemplate
- Zizq::Resources::Job
- Defined in:
- lib/zizq/resources/job.rb
Overview
Typed wrapper around a job response hash.
Inherits template fields (type, queue, priority, payload, backoff, retention, unique_key, unique_while) from JobTemplate and adds lifecycle fields and action methods.
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#attempts ⇒ Object
: () -> Integer.
-
#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.
-
#ready_at ⇒ Object
: () -> Float?.
-
#status ⇒ Object
: () -> String.
-
#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 JobTemplate
#backoff, #payload, #priority, #queue, #retention, #retry_limit, #type, #unique_key, #unique_while
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Zizq::Resources::Resource
Instance Method Details
#attempts ⇒ Object
: () -> Integer
18 |
# File 'lib/zizq/resources/job.rb', line 18 def attempts = @data["attempts"] #: () -> Integer |
#complete! ⇒ Object
Mark this job as successfully completed.
35 36 37 |
# File 'lib/zizq/resources/job.rb', line 35 def complete! #: () -> nil @client.report_success(id) end |
#completed_at ⇒ Object
: () -> Float?
21 |
# File 'lib/zizq/resources/job.rb', line 21 def completed_at = ms_to_seconds(@data["completed_at"]) #: () -> Float? |
#delete ⇒ Object
Delete this job.
54 55 56 |
# File 'lib/zizq/resources/job.rb', line 54 def delete @client.delete_job(id) end |
#dequeued_at ⇒ Object
: () -> Float?
19 |
# File 'lib/zizq/resources/job.rb', line 19 def dequeued_at = ms_to_seconds(@data["dequeued_at"]) #: () -> Float? |
#duplicate? ⇒ Boolean
: () -> bool
22 |
# File 'lib/zizq/resources/job.rb', line 22 def duplicate? = @data["duplicate"] == true #: () -> bool |
#errors(order: nil, limit: nil, page_size: nil) ⇒ Object
Fetch the error history for this job.
30 31 32 |
# File 'lib/zizq/resources/job.rb', line 30 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.
47 48 49 |
# File 'lib/zizq/resources/job.rb', line 47 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?
20 |
# File 'lib/zizq/resources/job.rb', line 20 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 |
#ready_at ⇒ Object
: () -> Float?
17 |
# File 'lib/zizq/resources/job.rb', line 17 def ready_at = ms_to_seconds(@data["ready_at"]) #: () -> Float? |
#status ⇒ Object
: () -> String
16 |
# File 'lib/zizq/resources/job.rb', line 16 def status = @data["status"] #: () -> String |
#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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/zizq/resources/job.rb', line 69 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 |