lib/kthxbye/job.rb in kthxbye-1.2.1 vs lib/kthxbye/job.rb in kthxbye-1.3.0
- old
+ new
@@ -55,11 +55,11 @@
# be sure we also remove it from the inactive queue
redis.srem("queue:#{queue}:inactive", id)
# remove the job's data as well
redis.hdel("data-store:#{queue}", id)
redis.hdel("result-store:#{queue}", id)
- redis.hdel( :faulure, id )
+ redis.hdel( :failure, id )
return ret
end
# Instantiates a job from a job id, a queue, and the job data.
@@ -67,11 +67,11 @@
# the job for running.
def initialize(id, queue, data)
@id = id.to_i
@queue = queue
@data = data
- @failed_attempts = Failure.fails_for_job(@id) # local tracking only, for rerun purposes
+ @failed_attempts = Failure.fails_for_job(@id) # local tracking only, for rerun purposes
end
# Simply requeues the job to be rerun.
def rerun
Job.add_to_queue( @id, @queue )
@@ -122,15 +122,20 @@
result = @klass.send(:perform, *@payload)
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
+ # handled by worker
+ raise ex
end
+ end
+
+ def fail(ex)
+ @failed_attempts += 1
+ log "Error occured: #{ex.message}. Try: #{@failed_attempts}/#{Kthxbye::Config.options[:attempts]}"
+ redis.publish("job.failed", @id)
+ Stats.incr("failures")
+ Kthxbye::Failure.create( self, ex )
end
# Removes the job from the inactive queue.
def active
redis.srem("jobs:inactive", @id)