Class: ActsAsTbackend::Client
- Inherits:
-
Object
- Object
- ActsAsTbackend::Client
- Defined in:
- lib/acts_as_tbackend/client.rb
Overview
The app-facing facade: a pooled, circuit-broken TBackend client. Checks the breaker, checks out a persistent Connection, delegates, and feeds transport health back to the breaker. Thread-safe (the Pool serialises per connection).
ActsAsTbackend.client.write_fact_once(fact)
ActsAsTbackend.client.facts_by_seq(store: "orders", after_seq: 0)
Every method returns the Connection's soft result hash
({ ok:, status:, committed:, retryable:, response:, error: }) — never raises for
a down daemon unless config.strict is set. When the breaker is open it
short-circuits with status "circuit_open" (retryable) without touching the socket.
Constant Summary collapse
- WRITE_STATUSES_OK =
%w[committed_acked idempotent_replay].freeze
Instance Method Summary collapse
- #facts_by_seq(**opts) ⇒ Object
- #facts_for(**opts) ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #latest_for(**opts) ⇒ Object
- #ping(**opts) ⇒ Object
- #shutdown ⇒ Object
- #write_fact_once(fact, **opts) ⇒ Object
- #write_fact_once_safe(fact, **opts) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 |
# File 'lib/acts_as_tbackend/client.rb', line 18 def initialize(config) @config = config @pool = Pool.new(config) @breaker = CircuitBreaker.new(threshold: config.breaker_threshold, cooldown: config.breaker_cooldown) end |
Instance Method Details
#facts_by_seq(**opts) ⇒ Object
40 41 42 |
# File 'lib/acts_as_tbackend/client.rb', line 40 def facts_by_seq(**opts) call { |c| c.facts_by_seq(**opts) } end |
#facts_for(**opts) ⇒ Object
36 37 38 |
# File 'lib/acts_as_tbackend/client.rb', line 36 def facts_for(**opts) call { |c| c.facts_for(**opts) } end |
#latest_for(**opts) ⇒ Object
32 33 34 |
# File 'lib/acts_as_tbackend/client.rb', line 32 def latest_for(**opts) call { |c| c.latest_for(**opts) } end |
#ping(**opts) ⇒ Object
44 45 46 |
# File 'lib/acts_as_tbackend/client.rb', line 44 def ping(**opts) call { |c| c.ping(**opts) } end |
#shutdown ⇒ Object
48 49 50 |
# File 'lib/acts_as_tbackend/client.rb', line 48 def shutdown @pool.shutdown end |
#write_fact_once(fact, **opts) ⇒ Object
24 25 26 |
# File 'lib/acts_as_tbackend/client.rb', line 24 def write_fact_once(fact, **opts) call { |c| c.write_fact_once(fact, **opts) } end |
#write_fact_once_safe(fact, **opts) ⇒ Object
28 29 30 |
# File 'lib/acts_as_tbackend/client.rb', line 28 def write_fact_once_safe(fact, **opts) call { |c| c.write_fact_once_safe(fact, **opts) } end |