Method: Resque::JobWithStatus#safe_perform!

Defined in:
lib/resque_ui/overrides/resque_status/job_with_status.rb

#safe_perform!Object

Run by the Resque::Worker when processing this job. It wraps the perform method ensuring that the final status of the job is set regardless of error. If an error occurs within the job’s work, it will set the status as failed and re-raise the error.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/resque_ui/overrides/resque_status/job_with_status.rb', line 69

def safe_perform!
  unless should_kill? || (status && status.killed?)
    set_status({'status' => 'working'})
    perform { |status| yield status if block_given?  }
    kill! if should_kill?
    completed unless status && status.completed?
    on_success if respond_to?(:on_success)
  end
rescue Killed
  logger.info "Job #{self} Killed at #{Time.now}"
  Resque::Status.killed(uuid)
  on_killed if respond_to?(:on_killed)
rescue => e
  logger.error e
  failed("The task failed because of an error: #{e}")
  if respond_to?(:on_failure)
    on_failure(e)
  else
    raise e
  end
end