Class: MigrateRunner
- Inherits:
-
Object
- Object
- MigrateRunner
- Defined in:
- app/services/migrate_runner.rb
Overview
It’s important to persist migrated ids because there may be some tasks in the execution queue for the same runner id
Constant Summary collapse
- TTL =
Rails.env.development? ? 10.hours : 1.hour
- KEY_PREFIX =
"migrated_ids"
Instance Attribute Summary collapse
-
#runner_id ⇒ Object
readonly
Returns the value of attribute runner_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(runner_id:) ⇒ MigrateRunner
constructor
A new instance of MigrateRunner.
- #migrate ⇒ Object
- #migrated? ⇒ Boolean
Constructor Details
#initialize(runner_id:) ⇒ MigrateRunner
Returns a new instance of MigrateRunner.
10 11 12 |
# File 'app/services/migrate_runner.rb', line 10 def initialize(runner_id:) @runner_id = runner_id end |
Instance Attribute Details
#runner_id ⇒ Object (readonly)
Returns the value of attribute runner_id.
8 9 10 |
# File 'app/services/migrate_runner.rb', line 8 def runner_id @runner_id end |
Class Method Details
.redis_client ⇒ Object
23 24 25 |
# File 'app/services/migrate_runner.rb', line 23 def self.redis_client Redis.new(RedisUrlParser.call(Settings.redis_url)) end |
Instance Method Details
#migrate ⇒ Object
14 15 16 17 |
# File 'app/services/migrate_runner.rb', line 14 def migrate Rails.logger.info("Migrate runner id #{runner_id}") self.class.redis_client.set("#{KEY_PREFIX}_#{runner_id}", 1, ex: TTL) end |
#migrated? ⇒ Boolean
19 20 21 |
# File 'app/services/migrate_runner.rb', line 19 def migrated? self.class.redis_client.exists?("#{KEY_PREFIX}_#{runner_id}") end |