Class: Webhookdb::Jobs::ReplicationMigration

Inherits:
Object
  • Object
show all
Extended by:
Async::Job
Defined in:
lib/webhookdb/jobs/replication_migration.rb

Overview

See Organization::enqueue_migrate_all_replication_tables for more info.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Async::Job

extended

Class Method Details

.migrate_org(org) ⇒ Object

To make mocking easier.



24
25
26
# File 'lib/webhookdb/jobs/replication_migration.rb', line 24

def self.migrate_org(org)
  org.migrate_replication_tables
end

Instance Method Details

#perform(org_id, target_release_created_at) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/webhookdb/jobs/replication_migration.rb', line 7

def perform(org_id, target_release_created_at)
  (org = Webhookdb::Organization[org_id]) or raise "Organization[#{org_id}] does not exist"
  target_rca = Time.parse(target_release_created_at)
  current_rca = Time.parse(Webhookdb::RELEASE_CREATED_AT)
  self.set_job_tags(organization_id: org_id, target_release_created_at:)
  if target_rca == current_rca
    self.class.migrate_org(org)
    self.set_job_tags(result: "ran_replication_migration_job")
  elsif target_rca > current_rca
    self.class.perform_in(1, org_id, target_release_created_at)
    self.set_job_tags(result: "reenqueued_replication_migration_job")
  else
    self.set_job_tags(result: "stale_replication_migration_job")
  end
end