class BackgroundWorker::WorkerExecution

Attributes

method_name[R]
options[R]
worker[R]

Public Class Methods

new(worker, options) click to toggle source
# File lib/background_worker/worker_execution.rb, line 5
def initialize(worker, options)
  @worker = worker
  @options = options
end

Public Instance Methods

call() click to toggle source
# File lib/background_worker/worker_execution.rb, line 10
def call
  worker.perform_now(options)
  report_implicitly_successful unless completed?

rescue StandardError => e
  log_worker_error(e)
  BackgroundWorker.after_exception(e)

ensure
  log_worker_finality
end

Private Instance Methods

completed?() click to toggle source
# File lib/background_worker/worker_execution.rb, line 24
def completed?
  worker.state.completed
end
log_worker_error(e) click to toggle source
# File lib/background_worker/worker_execution.rb, line 32
def log_worker_error(e)
  worker.log("Implicit failure: Exception: #{e}", severity: :error)
  worker.report_failed("An unhandled error occurred: #{e}") unless completed?
end
log_worker_finality() click to toggle source
# File lib/background_worker/worker_execution.rb, line 37
def log_worker_finality
  worker.log "Final state: #{worker.state.data}"
  worker.log "Job was #{worker.state.status}"
end
report_implicitly_successful() click to toggle source
# File lib/background_worker/worker_execution.rb, line 28
def report_implicitly_successful
  worker.report_successful
end