lib/wcc/contentful/configuration.rb in wcc-contentful-1.2.0 vs lib/wcc/contentful/configuration.rb in wcc-contentful-1.2.1

- old
+ new

@@ -1,26 +1,28 @@ # frozen_string_literal: true # This object contains all the configuration options for the `wcc-contentful` gem. class WCC::Contentful::Configuration ATTRIBUTES = %i[ - space access_token app_url - management_token - environment - default_locale - preview_token - webhook_username - webhook_password - webhook_jobs connection connection_options - update_schema_file + default_locale + environment + instrumentation_adapter + management_token + preview_token schema_file + space store - instrumentation_adapter + sync_retry_limit + sync_retry_wait + update_schema_file + webhook_jobs + webhook_password + webhook_username ].freeze # (required) Sets the Contentful Space ID. attr_accessor :space # (required) Sets the Content Delivery API access token. @@ -55,10 +57,21 @@ # # See the source code for WCC::Contentful::SyncEngine::Job for an example of how # to implement a webhook job. attr_accessor :webhook_jobs + # Sets the maximum number of times that the SyncEngine will retry synchronization + # when it detects that the Contentful CDN's cache has not been updated after a webhook. + # Default: 2 + attr_accessor :sync_retry_limit + + # Sets the base ActiveSupport::Duration that the SyncEngine will wait before retrying. + # Each subsequent retry uses an exponential backoff, so the second retry will be + # after (2 * sync_retry_wait), the third after (4 * sync_retry_wait), etc. + # Default: 2.seconds + attr_accessor :sync_retry_wait + # Returns true if the currently configured environment is pointing at `master`. def master? !environment.present? end @@ -143,13 +156,11 @@ # [:always] wcc-contentful will check either the management API or the CDN for the # most up-to-date content types and will raise a # WCC::Contentful::InitializationError if the API cannot be reached. def update_schema_file=(sym) valid_syms = %i[never if_possible if_missing always] - unless valid_syms.include?(sym) - raise ArgumentError, "update_schema_file must be one of #{valid_syms}" - end + raise ArgumentError, "update_schema_file must be one of #{valid_syms}" unless valid_syms.include?(sym) @update_schema_file = sym end attr_reader :update_schema_file @@ -170,25 +181,27 @@ # emit instrumentation events. The object or module provided here must respond # to :instrument like ActiveSupport::Notifications.instrument attr_accessor :instrumentation_adapter def initialize - @access_token = ENV['CONTENTFUL_ACCESS_TOKEN'] - @app_url = ENV['APP_URL'] + @access_token = ENV.fetch('CONTENTFUL_ACCESS_TOKEN', nil) + @app_url = ENV.fetch('APP_URL', nil) @connection_options = { api_url: 'https://cdn.contentful.com/', preview_api_url: 'https://preview.contentful.com/', management_api_url: 'https://api.contentful.com' } - @management_token = ENV['CONTENTFUL_MANAGEMENT_TOKEN'] - @preview_token = ENV['CONTENTFUL_PREVIEW_TOKEN'] - @space = ENV['CONTENTFUL_SPACE_ID'] + @management_token = ENV.fetch('CONTENTFUL_MANAGEMENT_TOKEN', nil) + @preview_token = ENV.fetch('CONTENTFUL_PREVIEW_TOKEN', nil) + @space = ENV.fetch('CONTENTFUL_SPACE_ID', nil) @default_locale = nil @middleware = [] @update_schema_file = :if_possible @schema_file = 'db/contentful-schema.json' @webhook_jobs = [] @store_factory = WCC::Contentful::Store::Factory.new(self, :direct) + @sync_retry_limit = 3 + @sync_retry_wait = 1.second end # Validates the configuration, raising ArgumentError if anything is wrong. This # is called by WCC::Contentful.init! def validate!