Class: Resque::JobChain::Step
- Inherits:
-
Object
- Object
- Resque::JobChain::Step
- Defined in:
- lib/resque/job_chain/step.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#job_class ⇒ Object
readonly
Returns the value of attribute job_class.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
-
#on_failure ⇒ Object
readonly
Returns the value of attribute on_failure.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Class Method Summary collapse
Instance Method Summary collapse
- #enqueue(chain_id, step_index, context) ⇒ Object
-
#initialize(job_class, args: {}, on_failure: nil, max_attempts: nil, queue: nil) ⇒ Step
constructor
A new instance of Step.
- #to_h ⇒ Object
Constructor Details
#initialize(job_class, args: {}, on_failure: nil, max_attempts: nil, queue: nil) ⇒ Step
Returns a new instance of Step.
8 9 10 11 12 13 14 |
# File 'lib/resque/job_chain/step.rb', line 8 def initialize(job_class, args: {}, on_failure: nil, max_attempts: nil, queue: nil) @job_class = job_class @args = args @on_failure = on_failure @max_attempts = max_attempts @queue = queue || job_class.instance_variable_get(:@queue) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/resque/job_chain/step.rb', line 6 def args @args end |
#job_class ⇒ Object (readonly)
Returns the value of attribute job_class.
6 7 8 |
# File 'lib/resque/job_chain/step.rb', line 6 def job_class @job_class end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
6 7 8 |
# File 'lib/resque/job_chain/step.rb', line 6 def max_attempts @max_attempts end |
#on_failure ⇒ Object (readonly)
Returns the value of attribute on_failure.
6 7 8 |
# File 'lib/resque/job_chain/step.rb', line 6 def on_failure @on_failure end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
6 7 8 |
# File 'lib/resque/job_chain/step.rb', line 6 def queue @queue end |
Class Method Details
.from_h(hash) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/resque/job_chain/step.rb', line 34 def self.from_h(hash) new( Object.const_get(hash['class']), args: hash['args'] || {}, on_failure: hash['on_failure']&.to_sym, max_attempts: hash['max_attempts'], queue: hash['queue']&.to_sym ) end |
Instance Method Details
#enqueue(chain_id, step_index, context) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/resque/job_chain/step.rb', line 16 def enqueue(chain_id, step_index, context) merged = stringify_keys(args) .merge(stringify_keys(context)) .merge('_chain_id' => chain_id, '_step_index' => step_index) Resque.enqueue_to(queue, job_class, merged) end |
#to_h ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/resque/job_chain/step.rb', line 24 def to_h { 'class' => job_class.to_s, 'args' => stringify_keys(args), 'on_failure' => on_failure&.to_s, 'max_attempts' => max_attempts, 'queue' => queue.to_s } end |