Class: RepositoryUpdateRemoteMirrorWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, Gitlab::ExclusiveLeaseHelpers
Defined in:
app/workers/repository_update_remote_mirror_worker.rb

Constant Summary collapse

UpdateError =
Class.new(StandardError)
LOCK_WAIT_TIME =
30.seconds
MAX_TRIES =
3

Constants included from Gitlab::ExclusiveLeaseHelpers

Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::ExclusiveLeaseHelpers

#in_lock

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#perform(remote_mirror_id, scheduled_time, tries = 0) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/workers/repository_update_remote_mirror_worker.rb', line 21

def perform(remote_mirror_id, scheduled_time, tries = 0)
  remote_mirror = RemoteMirror.find_by_id(remote_mirror_id)
  return unless remote_mirror
  return if remote_mirror.updated_since?(scheduled_time)

  # If the update is already running, wait for it to finish before running again
  # This will wait for a total of 90 seconds in 3 steps
  in_lock(
    remote_mirror_update_lock(remote_mirror.id),
    retries: 3,
    ttl: remote_mirror.max_runtime,
    sleep_sec: LOCK_WAIT_TIME
  ) do
    update_mirror(remote_mirror, scheduled_time, tries)
  end
rescue Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError
  # If an update runs longer than 1.5 minutes, we'll reschedule it
  # with a backoff. The next run will check if the previous update would
  # include the changes that triggered this update and become a no-op.
  self.class.perform_in(remote_mirror.backoff_delay, remote_mirror.id, scheduled_time, tries)
end