Class: Consyncful::SyncRunner
- Inherits:
-
Object
- Object
- Consyncful::SyncRunner
- Defined in:
- lib/consyncful/sync_runner.rb
Overview
The SyncRunner is responsible for continuously executing Contentful sync jobs at a configurable interval or in response to webhook signals.
Modes:
-
:poll — runs the sync every N seconds (default 15)
-
:webhook — waits for webhook signals and triggers a sync when received
Behavior:
-
Starts with an initial sync (‘Consyncful::Sync.latest.run`).
-
In poll mode, sleeps for the configured interval and then re-runs sync.
-
In webhook mode, listens for webhook signals and runs sync immediately.
Constant Summary collapse
- DEFAULT_INTERVAL =
15- VALID_MODES =
%i[poll webhook].freeze
Instance Method Summary collapse
-
#initialize(seconds: nil, mode: nil) ⇒ SyncRunner
constructor
A new instance of SyncRunner.
- #run ⇒ Object
Constructor Details
#initialize(seconds: nil, mode: nil) ⇒ SyncRunner
Returns a new instance of SyncRunner.
19 20 21 22 |
# File 'lib/consyncful/sync_runner.rb', line 19 def initialize(seconds: nil, mode: nil) @interval = seconds&.to_i || DEFAULT_INTERVAL @mode = validate_mode(mode) end |
Instance Method Details
#run ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/consyncful/sync_runner.rb', line 24 def run current_sync = Consyncful::Sync.latest current_sync.run # Run initial sync loop do sleep(@interval) current_sync.run if @mode == :poll || Consyncful::Sync.consume_webhook_signal! end end |