Class: Textus::Domain::Jobs::Job
- Inherits:
-
Object
- Object
- Textus::Domain::Jobs::Job
- Defined in:
- lib/textus/domain/jobs/job.rb
Overview
A unit of deferred work. Pure data. The id is ‘<type>:<digest>` where the digest is over the args with sorted keys, so logically-identical enqueues collide on the same id — which is how the Queue dedups (the file already exists). At-least-once delivery means handlers must be idempotent.
Constant Summary collapse
- DIGEST_BYTES =
16
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#attempts ⇒ Object
Returns the value of attribute attempts.
-
#enqueued_by ⇒ Object
readonly
Returns the value of attribute enqueued_by.
-
#last_error ⇒ Object
Returns the value of attribute last_error.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(type:, args:, enqueued_by: nil, attempts: 0, max_attempts: 3, last_error: nil) ⇒ Job
constructor
A new instance of Job.
- #to_h ⇒ Object
Constructor Details
#initialize(type:, args:, enqueued_by: nil, attempts: 0, max_attempts: 3, last_error: nil) ⇒ Job
Returns a new instance of Job.
17 18 19 20 21 22 23 24 |
# File 'lib/textus/domain/jobs/job.rb', line 17 def initialize(type:, args:, enqueued_by: nil, attempts: 0, max_attempts: 3, last_error: nil) @type = type.to_s @args = stringify(args) @enqueued_by = enqueued_by @attempts = attempts @max_attempts = max_attempts @last_error = last_error end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
14 15 16 |
# File 'lib/textus/domain/jobs/job.rb', line 14 def args @args end |
#attempts ⇒ Object
Returns the value of attribute attempts.
15 16 17 |
# File 'lib/textus/domain/jobs/job.rb', line 15 def attempts @attempts end |
#enqueued_by ⇒ Object (readonly)
Returns the value of attribute enqueued_by.
14 15 16 |
# File 'lib/textus/domain/jobs/job.rb', line 14 def enqueued_by @enqueued_by end |
#last_error ⇒ Object
Returns the value of attribute last_error.
15 16 17 |
# File 'lib/textus/domain/jobs/job.rb', line 15 def last_error @last_error end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
14 15 16 |
# File 'lib/textus/domain/jobs/job.rb', line 14 def max_attempts @max_attempts end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/textus/domain/jobs/job.rb', line 14 def type @type end |
Class Method Details
.from_h(hash) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/textus/domain/jobs/job.rb', line 37 def self.from_h(hash) new( type: hash["type"], args: hash["args"] || {}, enqueued_by: hash["enqueued_by"], attempts: hash["attempts"] || 0, max_attempts: hash["max_attempts"] || 3, last_error: hash["last_error"] ) end |
Instance Method Details
#id ⇒ Object
26 27 28 |
# File 'lib/textus/domain/jobs/job.rb', line 26 def id "#{@type}:#{digest}" end |
#to_h ⇒ Object
30 31 32 33 34 35 |
# File 'lib/textus/domain/jobs/job.rb', line 30 def to_h { "type" => @type, "args" => @args, "enqueued_by" => @enqueued_by, "attempts" => @attempts, "max_attempts" => @max_attempts, "last_error" => @last_error } end |