How can I programmatically fail a job in Sidekiq?
Calling system('some_command')
inside a perform()
function always return a successful job.
I want to fail a job based on a condition like this:
def perform(data)
output = system('some_command')
if output
# return this job as :success
else
# return this job as :fail
end
end
Thanks in advance
I think if you just raise an exception, it will make the sidekiq job fail :
def perform(data)
output = system('some_command')
raise StandardError, "my error is so sexy" unless output
end
Of course, you should replace the dumb error message I wrote by something meaningful.
NOTE: unless x
is just the same as if !x