lib/kthxbye/job.rb in kthxbye-1.0.5 vs lib/kthxbye/job.rb in kthxbye-1.1.0
- old
+ new
@@ -109,10 +109,12 @@
# Does all the heavy lifting of performing the job and storing the results.
# It will get the jobs class, payload and then run the job, storing the
# result in the result's store once complete. Also responsible for reporting
# errors and storing the job in the failure listing if an exception occurs.
+ # Will also publish a message on the job.failed channel (Redis PUBSUB) with
+ # the id of the failed job
def perform
begin
@klass = Object.const_get(@data['klass'])
@payload = @data['payload']
#set job active, getting ready to run
@@ -122,9 +124,10 @@
redis.hset( "result-store:#{@queue}", @id, encode( result ) )
return result
rescue Object => ex
@failed_attempts += 1
log "Error occured: #{ex.message}. Try: #{@failed_attempts}/#{Kthxbye::Config.options[:attempts]}"
+ redis.publish("job.failed", @id)
return Kthxbye::Failure.create( self, ex ) if @failed_attempts >= Kthxbye::Config.options[:attempts]
perform
end
end