lib/tobox/plugins/progress.rb in tobox-0.6.0 vs lib/tobox/plugins/progress.rb in tobox-0.6.1

- old
+ new

@@ -8,16 +8,37 @@ end module FetcherMethods private - def initialize(_, configuration) - super + def do_fetch_events + # mark events as invisible by using run_at as a visibility timeout + mark_as_fetched_params = { + run_at: Sequel.date_add( + Sequel::CURRENT_TIMESTAMP, + seconds: @configuration[:visibility_timeout] + ), + attempts: Sequel[@table][:attempts] + 1, + last_error: nil + } - @mark_as_fetched_params[:run_at] = Sequel.date_add( - Sequel::CURRENT_TIMESTAMP, - seconds: configuration[:visibility_timeout] - ) + if @ds.supports_returning?(:update) + @ds.where(id: fetch_event_ids).returning.update(mark_as_fetched_params) + else + event_ids = fetch_event_ids.select_map(:id) + events_ds = @ds.where(id: event_ids) + events_ds.update(mark_as_fetched_params) + events_ds.first(@batch_size) + end + end + + def calculate_event_retry_interval(attempts) + super(attempts - 1) + end + + def set_event_retry_attempts(event, update_params) + update_params.delete(:attempts) + super end def events_tr yield end