Class: Sidekiq::Sequence::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/sequence/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Base

Returns a new instance of Base.



24
25
26
27
28
29
# File 'lib/sidekiq/sequence/base.rb', line 24

def initialize(data = {})
  record = Record.create(data: data)

  # Start first job in the sequence.
  self.class.steps.first.constantize.perform_async record.id
end

Class Attribute Details

.stepsObject (readonly)

Returns the value of attribute steps.



7
8
9
# File 'lib/sidekiq/sequence/base.rb', line 7

def steps
  @steps
end

Class Method Details

.perform_step(index, id) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/sidekiq/sequence/base.rb', line 15

def self.perform_step(index, id)
  if index >= steps.size
    # No more steps in the sequence, so delete the record.
    Record.destroy id
  else
    steps[index].constantize.perform_async id
  end
end

.step(worker_class) ⇒ Object



9
10
11
12
# File 'lib/sidekiq/sequence/base.rb', line 9

def step(worker_class)
  @steps = [] if steps.nil?
  @steps << worker_class.name
end