Welcome to mirror list, hosted at ThFree Co, Russian Federation.

handling_retried_jobs_shared_context.rb « jobs « shared_contexts « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 428eff77373b22fcb601497408c32e732b1cbae7 (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
# frozen_string_literal: true

RSpec.shared_context 'when handling retried jobs' do |url|
  let(:set_name) { 'retry' }
  # Account for Sidekiq retry jitter
  # https://github.com/mperham/sidekiq/blob/3575ccb44c688dd08bfbfd937696260b12c622fb/lib/sidekiq/job_retry.rb#L217
  let(:schedule_jitter) { 10 }

  # Try to mimic as closely as possible what Sidekiq will actually
  # do to retry a job.
  def retry_in(klass, time, args = 0)
    message = Gitlab::Json.generate(
      'class' => klass.name,
      'args' => [args],
      'retry' => true
    )

    allow(klass).to receive(:sidekiq_retry_in_block).and_return(proc { time.to_i })

    begin
      Sidekiq::JobRetry.new(Sidekiq).local(klass, message, klass.queue) { raise 'boom' }
    rescue Sidekiq::JobRetry::Skip
      # Sidekiq scheduled the retry
    end
  end
end