Class: Sumologic::Search::Poller
- Inherits:
-
Object
- Object
- Sumologic::Search::Poller
- Defined in:
- lib/sumologic/search/poller.rb
Overview
Handles adaptive polling of search jobs with exponential backoff
Instance Method Summary collapse
-
#initialize(http_client:, config:) ⇒ Poller
constructor
A new instance of Poller.
-
#poll(job_id) ⇒ Object
Poll until job completes or times out Returns final job status data Starts polling immediately, then applies exponential backoff.
Constructor Details
#initialize(http_client:, config:) ⇒ Poller
Returns a new instance of Poller.
7 8 9 10 |
# File 'lib/sumologic/search/poller.rb', line 7 def initialize(http_client:, config:) @http = http_client @config = config end |
Instance Method Details
#poll(job_id) ⇒ Object
Poll until job completes or times out Returns final job status data Starts polling immediately, then applies exponential backoff
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sumologic/search/poller.rb', line 15 def poll(job_id) start_time = Time.now interval = @config.initial_poll_interval poll_count = 0 loop do check_timeout!(start_time) data = fetch_job_status(job_id) state = data['state'] log_poll_status(state, data, interval, poll_count) case state when 'DONE GATHERING RESULTS' log_completion(start_time, poll_count) return data when 'CANCELLED', 'FORCE PAUSED' raise Error, "Search job #{state.downcase}" end # Sleep after checking status (not before first check) sleep interval poll_count += 1 interval = calculate_next_interval(interval) end end |