Class: InstagramConnect::ReplayEventsJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/instagram_connect/replay_events_job.rb

Overview

Re-runs banked webhook events through the current handlers.

This is the payoff for storing raw payloads. Two situations need it, and neither is recoverable any other way, because Meta does not re-deliver:

- A field was subscribed before the gem could parse it. Its events banked
as `unhandled`; once the handler ships, replay them and the history is
complete rather than starting from the deploy.
- A handler had a bug. The events are marked `failed` with the error;
fix the bug, replay, and no data was lost in between.

Replaying is safe to repeat: handlers write through the same upserts and unique indexes the live path uses.

Instance Method Summary collapse

Instance Method Details

#perform(field: nil, since: nil, limit: 500, config: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'app/jobs/instagram_connect/replay_events_job.rb', line 18

def perform(field: nil, since: nil, limit: 500, config: nil)
  configuration = config || InstagramConnect.configuration

  scope = WebhookEvent.replayable.chronological.limit(limit)
  scope = scope.for_field(field) if field.present?
  scope = scope.where(created_at: since..) if since.present?

  scope.find_each do |event|
    replay(event, configuration)
  end
end