Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gudata/5574379 to your computer and use it in GitHub Desktop.
Save gudata/5574379 to your computer and use it in GitHub Desktop.
class SampleJob
def perform
begin
# do all your work in the begin block.
puts "hello world"
rescue Exception => e
# rescue any errors so that you know something went wrong. Email yourself the error if you need.
error_msg = "#{Time.now} ERROR (SampleJob#perform): #{e.message} - (#{e.class})\n#{(e.backtrace or []).join("\n")}"
puts error_msg
ensure
# make sure the job gets requeued. the ensure block is always executed, even if there was an exception thrown and caught by rescue.
Delayed::Job.enqueue SampleJob.new, 5, 1.hour.from_now
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment