Commit a728e96e authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'optimize-running-stuck-6' into 'master'

New Query Optimization For Running Stuck Jobs

See merge request gitlab-org/gitlab!71601
parents 8a0329d7 aa8b9434
......@@ -17,8 +17,11 @@ module Ci
def running_timed_out_builds
if Feature.enabled?(:ci_new_query_for_running_stuck_jobs, default_enabled: :yaml)
running_builds = Ci::Build.running.created_at_before(BUILD_RUNNING_OUTDATED_TIMEOUT.ago).order(created_at: :asc, project_id: :asc) # rubocop: disable CodeReuse/ActiveRecord
Ci::Build.id_in(running_builds).updated_at_before(BUILD_RUNNING_OUTDATED_TIMEOUT.ago)
Ci::Build
.running
.created_at_before(BUILD_RUNNING_OUTDATED_TIMEOUT.ago)
.updated_at_before(BUILD_RUNNING_OUTDATED_TIMEOUT.ago)
.order(created_at: :asc, project_id: :asc) # rubocop:disable CodeReuse/ActiveRecord
else
Ci::Build.running.updated_at_before(BUILD_RUNNING_OUTDATED_TIMEOUT.ago)
end
......
......@@ -4,19 +4,10 @@ require 'spec_helper'
RSpec.describe Ci::StuckBuilds::DropRunningService do
let!(:runner) { create :ci_runner }
let!(:job) { create :ci_build, runner: runner }
let(:created_at) { }
let(:updated_at) { }
let!(:job) { create(:ci_build, runner: runner, created_at: created_at, updated_at: updated_at, status: status) }
subject(:service) { described_class.new }
before do
job_attributes = { status: status }
job_attributes[:created_at] = created_at if created_at
job_attributes[:updated_at] = updated_at if updated_at
job.update!(job_attributes)
end
around do |example|
freeze_time { example.run }
end
......@@ -52,7 +43,7 @@ RSpec.describe Ci::StuckBuilds::DropRunningService do
include_examples 'running builds'
context 'when ci_new_query_for_running_stuck_jobs flag is disabled' do
context 'when new query flag is disabled' do
before do
stub_feature_flags(ci_new_query_for_running_stuck_jobs: false)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment