Class: SidekiqRobustJob::SidekiqJobManager

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_robust_job/sidekiq_job_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(jobs_repository:, clock:, digest_generator:, memory_monitor:) ⇒ SidekiqJobManager

Returns a new instance of SidekiqJobManager.



6
7
8
9
10
11
# File 'lib/sidekiq_robust_job/sidekiq_job_manager.rb', line 6

def initialize(jobs_repository:, clock:, digest_generator:, memory_monitor:)
  @jobs_repository = jobs_repository
  @clock = clock
  @digest_generator = digest_generator
  @memory_monitor = memory_monitor
end

Instance Method Details

#perform(job_id) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/sidekiq_robust_job/sidekiq_job_manager.rb', line 44

def perform(job_id)
  job = jobs_repository.find(job_id)
  return if job.unprocessable?

  job.started(memory_monitor: memory_monitor)
  jobs_repository.save(job)
  job.execute
end

#perform_async(job_class, *arguments) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/sidekiq_robust_job/sidekiq_job_manager.rb', line 13

def perform_async(job_class, *arguments)
  job = create_job(job_class, *arguments)
  return if job.unprocessable?
  job_class.original_perform_async(job.id).tap do |sidekiq_jid|
    job.assign_sidekiq_data(execute_at: clock.now, sidekiq_jid: sidekiq_jid)
    jobs_repository.save(job)
  end
end

#perform_at(job_class, time, *arguments) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/sidekiq_robust_job/sidekiq_job_manager.rb', line 31

def perform_at(job_class, time, *arguments)
  job = create_job(job_class, *arguments)
  return if job.unprocessable?
  job_class.original_perform_at(time, job.id).tap do |sidekiq_jid|
    job.assign_sidekiq_data(execute_at: time, sidekiq_jid: sidekiq_jid)
    jobs_repository.save(job)
  end
end

#perform_in(job_class, interval, *arguments) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/sidekiq_robust_job/sidekiq_job_manager.rb', line 22

def perform_in(job_class, interval, *arguments)
  job = create_job(job_class, *arguments)
  return if job.unprocessable?
  job_class.original_perform_in(interval, job.id).tap do |sidekiq_jid|
    job.assign_sidekiq_data(execute_at: clock.now + interval, sidekiq_jid: sidekiq_jid)
    jobs_repository.save(job)
  end
end

#set(job_class, options = {}) ⇒ Object



40
41
42
# File 'lib/sidekiq_robust_job/sidekiq_job_manager.rb', line 40

def set(job_class, options = {})
  SidekiqRobustJob::DependenciesContainer["setter_proxy_job"].build(job_class, options)
end