Commit 853e6391 authored by Sean Arnold's avatar Sean Arnold Committed by Douglas Barbosa Alexandre

Add migration to enqueue background worker

Changelog: added
parent e5bea80c
# frozen_string_literal: true
class BackfillIncidentIssueEscalationStatuses < Gitlab::Database::Migration[1.0]
MIGRATION = 'BackfillIncidentIssueEscalationStatuses'
DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 10_000
disable_ddl_transaction!
class Issue < ActiveRecord::Base
include EachBatch
self.table_name = 'issues'
scope :incidents, -> { where(issue_type: 1) }
end
def up
relation = Issue.incidents
queue_background_migration_jobs_by_range_at_intervals(
relation, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
end
def down
# no-op
end
end
a7aa1ffccce785d365720309e3773f167075a9d06805eea941e6cd47bc918471
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe BackfillIncidentIssueEscalationStatuses do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:issues) { table(:issues) }
let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') }
let(:project) { projects.create!(namespace_id: namespace.id) }
before do
stub_const("#{described_class.name}::BATCH_SIZE", 1)
end
it 'schedules jobs for incident issues' do
issues.create!(project_id: project.id) # non-incident issue
incident_1 = issues.create!(project_id: project.id, issue_type: 1)
incident_2 = issues.create!(project_id: project.id, issue_type: 1)
Sidekiq::Testing.fake! do
freeze_time do
migrate!
expect(described_class::MIGRATION).to be_scheduled_delayed_migration(
2.minutes, incident_1.id, incident_1.id)
expect(described_class::MIGRATION).to be_scheduled_delayed_migration(
4.minutes, incident_2.id, incident_2.id)
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
end
end
end
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