Class: Resque::JobChain::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/job_chain/chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, steps:, default_strategy: nil, initial_context: {}) ⇒ Chain

Returns a new instance of Chain.



6
7
8
9
10
11
# File 'lib/resque/job_chain/chain.rb', line 6

def initialize(id:, steps:, default_strategy: nil, initial_context: {})
  @id = id
  @steps = steps
  @default_strategy = default_strategy || JobChain.configuration.default_strategy
  @initial_context = initial_context
end

Instance Attribute Details

#default_strategyObject (readonly)

Returns the value of attribute default_strategy.



4
5
6
# File 'lib/resque/job_chain/chain.rb', line 4

def default_strategy
  @default_strategy
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/resque/job_chain/chain.rb', line 4

def id
  @id
end

#initial_contextObject (readonly)

Returns the value of attribute initial_context.



4
5
6
# File 'lib/resque/job_chain/chain.rb', line 4

def initial_context
  @initial_context
end

#stepsObject (readonly)

Returns the value of attribute steps.



4
5
6
# File 'lib/resque/job_chain/chain.rb', line 4

def steps
  @steps
end

Instance Method Details

#start!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/resque/job_chain/chain.rb', line 13

def start!
  started = Persistence.start_chain(
    chain_id: id,
    steps: steps,
    context: initial_context
  )

  if started
    steps.first.enqueue(id, 0, initial_context)
    Observable.notify(:chain_started, id)
  end

  started
end

#total_stepsObject



28
29
30
# File 'lib/resque/job_chain/chain.rb', line 28

def total_steps
  steps.length
end