Class: Webhookdb::Jobs::Backfill

Inherits:
Object
  • Object
show all
Extended by:
Async::Job
Includes:
Amigo::DurableJob, Amigo::QueueBackoffJob
Defined in:
lib/webhookdb/jobs/backfill.rb

Instance Method Summary collapse

Methods included from Async::Job

extended

Methods included from Amigo::DurableJob

enabled?, ensure_jobs_tables, heartbeat, heartbeat!, included, insert_job, lock_job, poll_jobs, reconnect, replace_database_settings, set_database_setting, storage_datasets, unlock_job

Instance Method Details

#_perform(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webhookdb/jobs/backfill.rb', line 21

def _perform(event)
  begin
    bfjob = self.lookup_model(Webhookdb::BackfillJob, event.payload)
  rescue RuntimeError => e
    self.logger.info "skipping_missing_backfill_job", error: e
    return
  end
  sint = bfjob.service_integration
  bflock = bfjob.ensure_service_integration_lock
  self.with_log_tags(sint.log_tags.merge(backfill_job_id: bfjob.opaque_id)) do
    sint.db.transaction do
      unless bflock.lock?
        self.logger.info "skipping_locked_backfill_job"
        bfjob.update(finished_at: Time.now)
        break
      end
      bfjob.refresh
      if bfjob.finished?
        self.logger.info "skipping_finished_backfill_job"
        break
      end
      begin
        sint.replicator.backfill(bfjob)
      rescue Webhookdb::Replicator::CredentialsMissing
        # The credentials could have been cleared out, so just finish this job.
        self.logger.info "skipping_backfill_job_without_credentials"
        bfjob.update(finished_at: Time.now)
        break
      end
    end
  end
end

#dependent_queuesObject



16
17
18
19
# File 'lib/webhookdb/jobs/backfill.rb', line 16

def dependent_queues
  # This is really the lowest-priority job so always defer to other queues.
  return super
end