Module: SidekiqRobustJob::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/sidekiq_robust_job/model.rb

Instance Method Summary collapse

Instance Method Details

#assign_sidekiq_data(execute_at:, sidekiq_jid:) ⇒ Object



86
87
88
89
# File 'lib/sidekiq_robust_job/model.rb', line 86

def assign_sidekiq_data(execute_at:, sidekiq_jid:)
  self.execute_at = execute_at
  self.sidekiq_jid = sidekiq_jid
end

#call(job_class_resolver: Object) ⇒ Object



82
83
84
# File 'lib/sidekiq_robust_job/model.rb', line 82

def call(job_class_resolver: Object)
  job_class_resolver.const_get(job_class).new.call(*arguments)
end

#completed(memory_monitor:, clock: SidekiqRobustJob.configuration.clock) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/sidekiq_robust_job/model.rb', line 47

def completed(memory_monitor:, clock: SidekiqRobustJob.configuration.clock)
  self.memory_usage_after_processing_in_megabytes = memory_monitor.mb
  self.memory_usage_change_in_megabytes = memory_usage_after_processing_in_megabytes - memory_usage_before_processing_in_megabytes
  self.completed_at = clock.now
  self.dropped_at = nil
  self.dropped_by_job_id = nil
  self.error_type = nil
  self.error_message = nil
  self.failed_at = nil
end

#completed?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/sidekiq_robust_job/model.rb', line 33

def completed?
  completed_at.present?
end

#drop(dropped_by_job_id:, clock: SidekiqRobustJob.configuration.clock) ⇒ Object



71
72
73
74
# File 'lib/sidekiq_robust_job/model.rb', line 71

def drop(dropped_by_job_id:, clock: SidekiqRobustJob.configuration.clock)
  self.dropped_at = clock.now
  self.dropped_by_job_id = dropped_by_job_id
end

#dropped?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/sidekiq_robust_job/model.rb', line 37

def dropped?
  dropped_at.present?
end

#executeObject



76
77
78
79
80
# File 'lib/sidekiq_robust_job/model.rb', line 76

def execute
  SidekiqRobustJob::DependenciesContainer["uniqueness_strategy_resolver"]
    .resolve(uniqueness_strategy)
    .execute(self)
end

#failed(error, clock: SidekiqRobustJob.configuration.clock) ⇒ Object



58
59
60
61
62
# File 'lib/sidekiq_robust_job/model.rb', line 58

def failed(error, clock: SidekiqRobustJob.configuration.clock)
  self.error_type = error.class
  self.error_message = error.message
  self.failed_at = clock.now
end

#reschedule(job_class_resolver: Object) ⇒ Object



64
65
66
67
68
69
# File 'lib/sidekiq_robust_job/model.rb', line 64

def reschedule(job_class_resolver: Object)
  sidekiq_job = job_class_resolver.const_get(job_class)
  interval_in_seconds = sidekiq_job.sidekiq_options.fetch("reschedule_interval_in_seconds", 5)

  sidekiq_job.original_perform_in(interval_in_seconds.seconds, id)
end

#started(memory_monitor:, clock: SidekiqRobustJob.configuration.clock) ⇒ Object



41
42
43
44
45
# File 'lib/sidekiq_robust_job/model.rb', line 41

def started(memory_monitor:, clock: SidekiqRobustJob.configuration.clock)
  self.memory_usage_before_processing_in_megabytes = memory_monitor.mb
  self.attempts += 1
  self.started_at = clock.now
end

#unprocessable?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/sidekiq_robust_job/model.rb', line 29

def unprocessable?
  completed? || dropped?
end