Class: ChainedJob::StartChains

Inherits:
Object
  • Object
show all
Defined in:
lib/chained_job/start_chains.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_class, array_of_job_arguments, parallelism) ⇒ StartChains

Returns a new instance of StartChains.



15
16
17
18
19
# File 'lib/chained_job/start_chains.rb', line 15

def initialize(job_class, array_of_job_arguments, parallelism)
  @job_class = job_class
  @array_of_job_arguments = array_of_job_arguments
  @parallelism = parallelism
end

Instance Attribute Details

#array_of_job_argumentsObject (readonly)

Returns the value of attribute array_of_job_arguments.



13
14
15
# File 'lib/chained_job/start_chains.rb', line 13

def array_of_job_arguments
  @array_of_job_arguments
end

#job_classObject (readonly)

Returns the value of attribute job_class.



13
14
15
# File 'lib/chained_job/start_chains.rb', line 13

def job_class
  @job_class
end

#parallelismObject (readonly)

Returns the value of attribute parallelism.



13
14
15
# File 'lib/chained_job/start_chains.rb', line 13

def parallelism
  @parallelism
end

Class Method Details

.run(job_class, array_of_job_arguments, parallelism) ⇒ Object



9
10
11
# File 'lib/chained_job/start_chains.rb', line 9

def self.run(job_class, array_of_job_arguments, parallelism)
  new(job_class, array_of_job_arguments, parallelism).run
end

Instance Method Details

#runObject

rubocop:disable Metrics/AbcSize



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chained_job/start_chains.rb', line 22

def run
  with_hooks do
    log_chained_job_cleanup

    ChainedJob::CleanUpQueue.run(job_class)

    next unless array_of_job_arguments.count.positive?

    ChainedJob::StoreJobArguments.run(job_class, job_tag, array_of_job_arguments)

    log_chained_job_start

    parallelism.times { |worked_id| job_class.perform_later(worked_id, job_tag) }
  end
end