summaryrefslogtreecommitdiff
path: root/app/workers/stuck_ci_jobs_worker.rb
blob: 72004f7568cc00e346560c8f2c7de70ace880a9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker
  include ApplicationWorker
  include ExclusiveLeaseGuard

  # rubocop:disable Scalability/CronWorkerContext
  # This is an instance-wide cleanup query, so there's no meaningful
  # scope to consider this in the context of.
  include CronjobQueue
  # rubocop:enable Scalability/CronWorkerContext

  data_consistency :always

  feature_category :continuous_integration

  def perform
    Ci::StuckBuilds::DropRunningWorker.perform_in(20.minutes)
    Ci::StuckBuilds::DropScheduledWorker.perform_in(40.minutes)

    try_obtain_lease do
      Ci::StuckBuilds::DropPendingService.new.execute
    end
  end

  private

  def lease_timeout
    30.minutes
  end
end