Class: Webhookdb::Jobs::IcalendarEnqueueSyncs
- Inherits:
-
Object
- Object
- Webhookdb::Jobs::IcalendarEnqueueSyncs
- Extended by:
- Async::ScheduledJob
- Defined in:
- lib/webhookdb/jobs/icalendar_enqueue_syncs.rb
Overview
For every IcalendarCalendar row needing a sync (across all service integrations), enqueue a Webhookdb::Jobs::IcalendarSync
job. Jobs are ‘splayed’ over 1/4 of the configured calendar sync period (see Webhookdb::Icalendar
) to avoid a thundering herd.
Instance Method Summary collapse
Methods included from Async::ScheduledJob
Instance Method Details
#_perform ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/webhookdb/jobs/icalendar_enqueue_syncs.rb', line 16 def _perform max_splay = Webhookdb::Icalendar.sync_period_hours.hours.to_i / 4 Webhookdb::ServiceIntegration.dataset.where_each(service_name: "icalendar_calendar_v1") do |sint| sint.replicator.admin_dataset do |ds| sint.replicator.rows_needing_sync(ds).each do |row| calendar_external_id = row.fetch(:external_id) self.(sint.) do splay = rand(1..max_splay) enqueued_job_id = Webhookdb::Jobs::IcalendarSync.perform_in(splay, sint.id, calendar_external_id) self.logger.debug("enqueued_icalendar_sync", calendar_external_id:, enqueued_job_id:) end end end end end |