Module: LoggingWorker::Worker

Defined in:
lib/logging_worker/worker.rb

Instance Method Summary collapse

Instance Method Details

#job_runObject



13
14
15
# File 'lib/logging_worker/worker.rb', line 13

def job_run
  @job_run ||= job_run_class.new
end

#job_run_classObject



5
6
7
8
9
10
11
# File 'lib/logging_worker/worker.rb', line 5

def job_run_class
  if sidekiq_options_hash && sidekiq_options_hash.has_key?("job_run_class")
    sidekiq_options_hash["job_run_class"]
  else
    LoggingWorker::JobRun
  end
end

#perform(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logging_worker/worker.rb', line 17

def perform(*args)
  job_run.worker_class = self.class.name
  job_run.arguments = args
  job_run.save!

  job_run.log_will_change!

  super

  job_run.successful!
rescue => e
  job_run.error_class = e.class.name
  job_run.error_message = e.message
  job_run.error_backtrace = e.backtrace
  job_run.save!
  raise e
ensure
  job_run.completed!
end