Class: Webhookdb::Replicator::Base::ServiceBackfiller

Inherits:
Backfiller
  • Object
show all
Defined in:
lib/webhookdb/replicator/base.rb

Overview

Basic backfiller that calls _fetch_backfill_page on the given replicator. Any timeouts or 5xx errors are automatically re-enqueued for a retry. This behavior can be customized somewhat setting :backfiller_server_error_retries (default to 2) and :backfiller_server_error_backoff on the replicator (default to 63 seconds), though customization beyond that should use a custom backfiller.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Backfiller

#_fetch_backfill_page_with_retry, #backfill, do_retry_wait, #max_backfill_retry_attempts, #wait_for_retry_attempt

Constructor Details

#initialize(svc) ⇒ ServiceBackfiller

Returns a new instance of ServiceBackfiller.



1079
1080
1081
1082
1083
1084
1085
# File 'lib/webhookdb/replicator/base.rb', line 1079

def initialize(svc)
  @svc = svc
  @server_error_retries = _getifrespondto(:backfiller_server_error_retries, 2)
  @server_error_backoff = _getifrespondto(:backfiller_server_error_backoff, 63.seconds)
  raise "#{svc} must implement :_fetch_backfill_page" unless svc.respond_to?(:_fetch_backfill_page)
  super()
end

Instance Attribute Details

#server_error_backoffObject

Returns the value of attribute server_error_backoff.



1077
1078
1079
# File 'lib/webhookdb/replicator/base.rb', line 1077

def server_error_backoff
  @server_error_backoff
end

#server_error_retriesObject

Returns the value of attribute server_error_retries.



1077
1078
1079
# File 'lib/webhookdb/replicator/base.rb', line 1077

def server_error_retries
  @server_error_retries
end

#svcObject

Returns the value of attribute svc.



1075
1076
1077
# File 'lib/webhookdb/replicator/base.rb', line 1075

def svc
  @svc
end

Instance Method Details

#__retryordieObject

Raises:

  • (Amigo::Retry::OrDie)


1105
1106
1107
# File 'lib/webhookdb/replicator/base.rb', line 1105

def __retryordie
  raise Amigo::Retry::OrDie.new(self.server_error_retries, self.server_error_backoff)
end

#fetch_backfill_page(pagination_token, last_backfilled:) ⇒ Object



1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/webhookdb/replicator/base.rb', line 1096

def fetch_backfill_page(pagination_token, last_backfilled:)
  return @svc._fetch_backfill_page(pagination_token, last_backfilled:)
rescue ::Timeout::Error, ::SocketError
  self.__retryordie
rescue Webhookdb::Http::Error => e
  self.__retryordie if e.status >= 500
  raise
end

#handle_item(item) ⇒ Object



1092
1093
1094
# File 'lib/webhookdb/replicator/base.rb', line 1092

def handle_item(item)
  return @svc.upsert_webhook_body(item)
end