class Sidekiq::Processor
def process(uow)
def process(uow) jobstr = uow.job queue = uow.queue_name # Treat malformed JSON as a special case: job goes straight to the morgue. job_hash = nil begin job_hash = Sidekiq.load_json(jobstr) rescue => ex now = Time.now.to_f redis do |conn| conn.multi do |xa| xa.zadd("dead", now.to_s, jobstr) xa.zremrangebyscore("dead", "-inf", now - @capsule.config[:dead_timeout_in_seconds]) xa.zremrangebyrank("dead", 0, - @capsule.config[:dead_max_jobs]) end end handle_exception(ex, {context: "Invalid JSON for job", jobstr: jobstr}) return uow.acknowledge end ack = false Thread.handle_interrupt(IGNORE_SHUTDOWN_INTERRUPTS) do Thread.handle_interrupt(ALLOW_SHUTDOWN_INTERRUPTS) do dispatch(job_hash, queue, jobstr) do |instance| config.server_middleware.invoke(instance, job_hash, queue) do execute_job(instance, job_hash["args"]) end end ack = true rescue Sidekiq::Shutdown # Had to force kill this job because it didn't finish # within the timeout. Don't acknowledge the work since # we didn't properly finish it. rescue Sidekiq::JobRetry::Skip => s # Skip means we handled this error elsewhere. We don't # need to log or report the error. ack = true raise s rescue Sidekiq::JobRetry::Handled => h # this is the common case: job raised error and Sidekiq::JobRetry::Handled # signals that we created a retry successfully. We can acknowledge the job. ack = true e = h.cause || h handle_exception(e, {context: "Job raised exception", job: job_hash}) raise e rescue Exception => ex # Unexpected error! This is very bad and indicates an exception that got past # the retry subsystem (e.g. network partition). We won't acknowledge the job # so it can be rescued when using Sidekiq Pro. handle_exception(ex, {context: "Internal exception!", job: job_hash, jobstr: jobstr}) raise ex end ensure if ack uow.acknowledge end end end