2019-08-20 11:25:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-01-19 13:14:01 -05:00
|
|
|
require 'sidekiq/job_retry'
|
|
|
|
|
2019-08-20 11:25:04 -04:00
|
|
|
module Gitlab
|
|
|
|
module SidekiqMiddleware
|
|
|
|
class Monitor
|
|
|
|
def call(worker, job, queue)
|
2019-09-18 14:06:14 -04:00
|
|
|
Gitlab::SidekiqDaemon::Monitor.instance.within_job(worker.class, job['jid'], queue) do
|
2019-08-20 11:25:04 -04:00
|
|
|
yield
|
|
|
|
end
|
2019-09-10 08:12:05 -04:00
|
|
|
rescue Gitlab::SidekiqDaemon::Monitor::CancelledError
|
2019-08-21 15:15:03 -04:00
|
|
|
# push job to DeadSet
|
|
|
|
payload = ::Sidekiq.dump_json(job)
|
|
|
|
::Sidekiq::DeadSet.new.kill(payload, notify_failure: false)
|
|
|
|
|
2019-08-21 06:03:42 -04:00
|
|
|
# ignore retries
|
2019-08-21 15:15:03 -04:00
|
|
|
raise ::Sidekiq::JobRetry::Skip
|
2019-08-20 11:25:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|