Module: ActsAsTbackend

Defined in:
lib/acts_as_tbackend.rb,
lib/acts_as_tbackend/fact.rb,
lib/acts_as_tbackend/pool.rb,
lib/acts_as_tbackend/client.rb,
lib/acts_as_tbackend/config.rb,
lib/acts_as_tbackend/mirror.rb,
lib/acts_as_tbackend/version.rb,
lib/acts_as_tbackend/extension.rb,
lib/acts_as_tbackend/connection.rb,
lib/acts_as_tbackend/circuit_breaker.rb,
lib/acts_as_tbackend/shadow_comparison.rb

Overview

Production connector for the TBackend temporal-ledger daemon.

ActsAsTbackend.configure do |c|
c.host = "127.0.0.1"; c.port = 7401
c.token = ENV["TBACKEND_TOKEN"]
c.pool_size = 12                 # ≈ Puma threads/process
end

id   = ActsAsTbackend::Fact.derive_id(store: "orders", record_id: o.id,
                                     event_type: "order.accepted", source_version: o.updated_at)
fact = ActsAsTbackend::Fact.build(id:, store: "orders", key: "order:#{o.id}", value: {...})
ActsAsTbackend.client.write_fact_once(fact)      # idempotent, pooled, circuit-broken

Layers, deliberately separate:

Connection — one persistent framed socket + protocol (not thread-safe)
Pool       — N connections, checkout per thread (connection_pool)
Client     — facade: pool + circuit breaker; the app-facing API

Defined Under Namespace

Modules: Extension, Fact, Mirror, ShadowComparison Classes: CircuitBreaker, Client, Config, Connection, Pool

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.clientObject

Shared pooled client. Thread-safe; memoized per process.



47
48
49
# File 'lib/acts_as_tbackend.rb', line 47

def client
  @client ||= Client.new(config)
end

.configObject



31
32
33
# File 'lib/acts_as_tbackend.rb', line 31

def config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



40
41
42
43
44
# File 'lib/acts_as_tbackend.rb', line 40

def configure
  yield config
  reset!
  config
end

.enabled?Boolean

Master kill-switch (Config#enabled). When false the extension callbacks no-op.

Returns:

  • (Boolean)


36
37
38
# File 'lib/acts_as_tbackend.rb', line 36

def enabled?
  config.enabled
end

.reset!Object

Rebuild pool + client. Call in the forking hook (Puma on_worker_boot, Sidekiq configure_server) so a child never inherits a parent's sockets.



53
54
55
56
57
58
# File 'lib/acts_as_tbackend.rb', line 53

def reset!
  old = @client
  @client = nil
  old&.shutdown
  nil
end