diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2019-02-27 08:08:34 +0300 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2019-03-01 17:49:20 +0300 |
commit | 7c8920c9dc6449f9d9a76dac619e6829398ec7db (patch) | |
tree | 0c7badbaf476e812a644e7c64580c84fe8e9f789 /app/workers/hashed_storage/base_worker.rb | |
parent | 4bae61005dd835c7c8bf3ce911328a8e8af86a93 (diff) |
Extract common logic to HashedStorage::BaseWorker
New class contains the ExclusiveLease specifics that is shared among
both the Migration and Rollback workers.
Diffstat (limited to 'app/workers/hashed_storage/base_worker.rb')
-rw-r--r-- | app/workers/hashed_storage/base_worker.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/workers/hashed_storage/base_worker.rb b/app/workers/hashed_storage/base_worker.rb new file mode 100644 index 00000000000..816e0504db6 --- /dev/null +++ b/app/workers/hashed_storage/base_worker.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module HashedStorage + class BaseWorker + include ExclusiveLeaseGuard + + LEASE_TIMEOUT = 30.seconds.to_i + LEASE_KEY_SEGMENT = 'project_migrate_hashed_storage_worker'.freeze + + protected + + def lease_key + # we share the same lease key for both migration and rollback so they don't run simultaneously + "#{LEASE_KEY_SEGMENT}:#{project_id}" + end + + def lease_timeout + LEASE_TIMEOUT + end + end +end |