Class: ForestAdminDatasourceRpc::Utils::SchemaPollingClient
- Inherits:
-
Object
- Object
- ForestAdminDatasourceRpc::Utils::SchemaPollingClient
- Defined in:
- lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb
Constant Summary collapse
- DEFAULT_POLLING_INTERVAL =
600- MIN_POLLING_INTERVAL =
1- MAX_POLLING_INTERVAL =
3600
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#current_schema ⇒ Object
readonly
Returns the value of attribute current_schema.
Instance Method Summary collapse
- #check_schema ⇒ Object
-
#initialize(uri, auth_secret, polling_interval: DEFAULT_POLLING_INTERVAL, introspection: nil, &on_schema_change) ⇒ SchemaPollingClient
constructor
A new instance of SchemaPollingClient.
- #start? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(uri, auth_secret, polling_interval: DEFAULT_POLLING_INTERVAL, introspection: nil, &on_schema_change) ⇒ SchemaPollingClient
Returns a new instance of SchemaPollingClient.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb', line 15 def initialize(uri, auth_secret, polling_interval: DEFAULT_POLLING_INTERVAL, introspection: nil, &on_schema_change) @uri = uri @auth_secret = auth_secret @polling_interval = polling_interval @on_schema_change = on_schema_change @closed = false @introspection_schema = introspection @current_schema = nil @connection_attempts = 0 @initial_sync_completed = false @client_id = uri validate_polling_interval! @rpc_client = RpcClient.new(@uri, @auth_secret) end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb', line 9 def client_id @client_id end |
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
9 10 11 |
# File 'lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb', line 9 def closed @closed end |
#current_schema ⇒ Object (readonly)
Returns the value of attribute current_schema.
9 10 11 |
# File 'lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb', line 9 def current_schema @current_schema end |
Instance Method Details
#check_schema ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb', line 60 def check_schema @connection_attempts += 1 log_checking_schema result = @rpc_client.fetch_schema('/forest/rpc-schema', if_none_match: @current_schema&.dig(:etag)) handle_schema_result(result) rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e log_connection_error(e) rescue ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient => e log_authentication_error(e) rescue ForestAdminDatasourceToolkit::Exceptions::ForestException => e log_rpc_error(e) rescue StandardError => e log_unexpected_error(e) end |
#start? ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb', line 33 def start? return false if @closed ForestAdminAgent::Facades::Container.logger&.log('Info', "Getting schema from RPC agent on #{@uri}.") fetch_initial_schema_sync # Register with the shared pool SchemaPollingPool.instance.register?(@client_id, self) ForestAdminAgent::Facades::Container.logger&.log( 'Info', "[Schema Polling] Registered with pool (interval: #{@polling_interval}s, client: #{@client_id})" ) true end |
#stop ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/forest_admin_datasource_rpc/Utils/schema_polling_client.rb', line 49 def stop return if @closed @closed = true ForestAdminAgent::Facades::Container.logger&.log('Debug', '[Schema Polling] Stopping polling') SchemaPollingPool.instance.unregister?(@client_id) ForestAdminAgent::Facades::Container.logger&.log('Debug', '[Schema Polling] Polling stopped') end |