Sha256: ecc788b2855270915020e40d343f0f6159741c3113e3011b37c4f15931a54b56

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module Tobox
  module Plugins
    module Progress
      def self.configure(conf)
        conf.config[:visibility_timeout] = 30
      end

      module FetcherMethods
        private

        def do_fetch_events
          # mark events as invisible

          # @type var mark_as_fetched_params: Hash[Symbol, untyped]
          mark_as_fetched_params = {
            last_error: nil
          }
          mark_as_fetched_params[@attempts_column] = Sequel[@table][@attempts_column] + 1 if @attempts_column

          mark_as_fetched_params[@visibility_column] = if @configuration.visibility_type_bool?
                                                         true
                                                       else
                                                         Sequel.date_add(
                                                           Sequel::CURRENT_TIMESTAMP,
                                                           seconds: @configuration[:visibility_timeout]
                                                         )
                                                       end

          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_column)
          super
        end

        def events_tr
          yield
        end

        def event_id_tr(&block)
          @db.transaction(savepoint: false, &block)
        end
      end
    end
    register_plugin :progress, Progress
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tobox-0.7.0 lib/tobox/plugins/progress.rb