lib/deimos/utils/db_poller/time_based.rb in deimos-ruby-1.22.2 vs lib/deimos/utils/db_poller/time_based.rb in deimos-ruby-1.22.3
- old
+ new
@@ -28,23 +28,26 @@
def process_updates
time_from = @config.full_table ? Time.new(0) : @info.last_sent.in_time_zone
time_to = Time.zone.now - @config.delay_time
Deimos.config.logger.info("Polling #{log_identifier} from #{time_from} to #{time_to}")
status = PollStatus.new(0, 0, 0)
+ first_batch = true
# poll_query gets all the relevant data from the database, as defined
# by the producer itself.
loop do
Deimos.config.logger.debug("Polling #{log_identifier}, batch #{status.current_batch}")
batch = fetch_results(time_from, time_to).to_a
- if batch.empty?
- @info.touch(:last_sent)
- break
- end
+ break if batch.empty?
+ first_batch = false
process_and_touch_info(batch, status)
time_from = last_updated(batch.last)
end
+
+ # If there were no results at all, we update last_sent so that we still get a wait
+ # before the next poll.
+ @info.touch(:last_sent) if first_batch
Deimos.config.logger.info("Poll #{log_identifier} complete at #{time_to} (#{status.report})")
end
# @param time_from [ActiveSupport::TimeWithZone]
# @param time_to [ActiveSupport::TimeWithZone]