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

background_migration_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 45ce49bb5c0b9432d52e4b7fe0ca0383accbe9d2 (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
32
33
34
35
36
37
38
39
class BackgroundMigrationWorker
  include Sidekiq::Worker
  include DedicatedSidekiqQueue

  # Enqueues a number of jobs in bulk.
  #
  # The `jobs` argument should be an Array of Arrays, each sub-array must be in
  # the form:
  #
  #     [migration-class, [arg1, arg2, ...]]
  def self.perform_bulk(jobs)
    Sidekiq::Client.push_bulk('class' => self,
                              'queue' => sidekiq_options['queue'],
                              'args' => jobs)
  end

  # Schedules multiple jobs in bulk, with a delay.
  #
  def self.perform_bulk_in(delay, jobs)
    now = Time.now.to_i
    schedule = now + delay.to_i

    if schedule <= now
      raise ArgumentError, 'The schedule time must be in the future!'
    end

    Sidekiq::Client.push_bulk('class' => self,
                              'queue' => sidekiq_options['queue'],
                              'args' => jobs,
                              'at' => schedule)
  end

  # Performs the background migration.
  #
  # See Gitlab::BackgroundMigration.perform for more information.
  def perform(class_name, arguments = [])
    Gitlab::BackgroundMigration.perform(class_name, arguments)
  end
end