Class: Gitlab::PhabricatorImport::BaseWorker
Overview
rubocop:disable Scalability/IdempotentWorker
Constant Summary
ExclusiveLeaseHelpers::FailedToObtainLockError
WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES
Class Method Summary
collapse
Instance Method Summary
collapse
#in_lock
Class Method Details
.add_job(project_id) ⇒ Object
33
34
35
|
# File 'app/workers/gitlab/phabricator_import/base_worker.rb', line 33
def add_job(project_id)
worker_state(project_id).add_job
end
|
.remove_job(project_id) ⇒ Object
37
38
39
|
# File 'app/workers/gitlab/phabricator_import/base_worker.rb', line 37
def remove_job(project_id)
worker_state(project_id).remove_job
end
|
.schedule(project_id, *args) ⇒ Object
28
29
30
31
|
# File 'app/workers/gitlab/phabricator_import/base_worker.rb', line 28
def schedule(project_id, *args)
perform_async(project_id, *args)
add_job(project_id)
end
|
.worker_state(project_id) ⇒ Object
Instance Method Details
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/workers/gitlab/phabricator_import/base_worker.rb', line 46
def perform(project_id, *args)
in_lock("#{self.class.name.underscore}/#{project_id}/#{args}", ttl: 2.hours, sleep_sec: 5.seconds) do
project = Project.find_by_id(project_id)
next unless project
next unless project.import_state&.in_progress?
project.import_state.refresh_jid_expiration
import(project, *args)
project.after_import if self.class.worker_state(project_id).running_count < 2
self.class.remove_job(project_id)
end
rescue Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError
self.class.perform_in(30.seconds, project_id, *args)
end
|