class WCC::Contentful::SyncEngine::Job
This job uses the Contentful
Sync API to update the configured store with the latest data from Contentful
.
Public Instance Methods
perform(event = nil)
click to toggle source
# File lib/wcc/contentful/sync_engine.rb, line 144 def perform(event = nil) return unless sync_engine&.should_sync? up_to_id = nil up_to_id = event[:up_to_id] || event.dig('sys', 'id') if event sync!(up_to_id: up_to_id) end
sync!(up_to_id: nil)
click to toggle source
Calls the Contentful
Sync API and updates the configured store with the returned data.
@param [String] up_to_id
An ID that we know has changed and should come back from the sync. If we don't find this ID in the sync data, then drop a job to try the sync again after a few minutes.
# File lib/wcc/contentful/sync_engine.rb, line 160 def sync!(up_to_id: nil) id_found, count = sync_engine.next(up_to_id: up_to_id) next_sync_token = sync_engine.state['token'] logger.info "Synced #{count} entries. Next sync token:\n #{next_sync_token}" logger.info "Should enqueue again? [#{!id_found}]" # Passing nil to only enqueue the job 1 more time sync_later!(up_to_id: nil) unless id_found next_sync_token end
sync_later!(up_to_id: nil, wait: 10.minutes)
click to toggle source
Drops an ActiveJob job to invoke WCC::Contentful.sync! after a given amount of time.
# File lib/wcc/contentful/sync_engine.rb, line 174 def sync_later!(up_to_id: nil, wait: 10.minutes) self.class.set(wait: wait) .perform_later(up_to_id: up_to_id) end