diff options
Diffstat (limited to 'app/workers/bulk_imports/entity_worker.rb')
-rw-r--r-- | app/workers/bulk_imports/entity_worker.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/workers/bulk_imports/entity_worker.rb b/app/workers/bulk_imports/entity_worker.rb index caee292a504..6ff2d15d6e8 100644 --- a/app/workers/bulk_imports/entity_worker.rb +++ b/app/workers/bulk_imports/entity_worker.rb @@ -3,9 +3,10 @@ module BulkImports class EntityWorker include ApplicationWorker + include ExclusiveLeaseGuard idempotent! - deduplicate :until_executed, if_deduplicated: :reschedule_once + deduplicate :until_executing data_consistency :always feature_category :importers sidekiq_options retry: 3, dead: false @@ -27,7 +28,10 @@ module BulkImports if running_tracker.present? log_info(message: 'Stage running', entity_stage: running_tracker.stage) else - start_next_stage + # Use lease guard to prevent duplicated workers from starting multiple stages + try_obtain_lease do + start_next_stage + end end re_enqueue @@ -78,6 +82,18 @@ module BulkImports end end + def lease_timeout + PERFORM_DELAY + end + + def lease_key + "gitlab:bulk_imports:entity_worker:#{entity.id}" + end + + def log_lease_taken + log_info(message: lease_taken_message) + end + def source_version entity.bulk_import.source_version_info.to_s end |