Class: MigrateRunner

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_idObject (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_clientObject



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

#migrateObject



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

Returns:

  • (Boolean)


19
20
21
# File 'app/services/migrate_runner.rb', line 19

def migrated?
  self.class.redis_client.exists?("#{KEY_PREFIX}_#{runner_id}")
end