Class: ChainedJob::Process

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, job_instance, job_arguments_key, worker_id, job_tag) ⇒ Process

Returns a new instance of Process.



13
14
15
16
17
18
19
# File 'lib/chained_job/process.rb', line 13

def initialize(args, job_instance, job_arguments_key, worker_id, job_tag)
  @args = args
  @job_instance = job_instance
  @job_arguments_key = job_arguments_key
  @worker_id = worker_id
  @job_tag = job_tag
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



11
12
13
# File 'lib/chained_job/process.rb', line 11

def args
  @args
end

#job_arguments_keyObject (readonly)

Returns the value of attribute job_arguments_key.



11
12
13
# File 'lib/chained_job/process.rb', line 11

def job_arguments_key
  @job_arguments_key
end

#job_instanceObject (readonly)

Returns the value of attribute job_instance.



11
12
13
# File 'lib/chained_job/process.rb', line 11

def job_instance
  @job_instance
end

#job_tagObject (readonly)

Returns the value of attribute job_tag.



11
12
13
# File 'lib/chained_job/process.rb', line 11

def job_tag
  @job_tag
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



11
12
13
# File 'lib/chained_job/process.rb', line 11

def worker_id
  @worker_id
end

Class Method Details

.run(args, job_instance, job_arguments_key, worker_id, job_tag) ⇒ Object



7
8
9
# File 'lib/chained_job/process.rb', line 7

def self.run(args, job_instance, job_arguments_key, worker_id, job_tag)
  new(args, job_instance, job_arguments_key, worker_id, job_tag).run
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chained_job/process.rb', line 21

def run
  with_hooks do
    return finished_worker unless argument

    begin
      job_instance.process(argument)
    rescue StandardError => e
      push_job_arguments_back if handle_retry?
      raise e
    end
    job_instance.class.perform_later(args, worker_id, job_tag)
  end
end