Class: BSV::Wallet::Daemon
- Inherits:
-
Object
- Object
- BSV::Wallet::Daemon
- Defined in:
- lib/bsv/wallet/daemon.rb
Overview
Background polling loop for entity-driven network interactions.
Periodically queries for entities needing push or fetch operations and dispatches them through Services. Each entity is processed independently – one failure does not block others.
The daemon does not import postgres models directly. Instead, it accepts callable query objects (lambdas, procs, or anything responding to call) that return arrays of Pushable/Fetchable entities. This keeps the wallet gem free of postgres dependencies.
Instance Method Summary collapse
-
#initialize(services:, pending_pushes: -> { [] }, stale_fetches: -> { [] }, pending_proofs: -> { [] }, interval: 30) ⇒ Daemon
constructor
A new instance of Daemon.
-
#run_cycle ⇒ Object
Execute one polling cycle.
-
#running? ⇒ Boolean
Whether the daemon is currently running.
-
#start ⇒ Object
Start the polling loop.
-
#stop ⇒ Object
Signal the loop to exit after the current cycle completes.
Constructor Details
#initialize(services:, pending_pushes: -> { [] }, stale_fetches: -> { [] }, pending_proofs: -> { [] }, interval: 30) ⇒ Daemon
Returns a new instance of Daemon.
31 32 33 34 35 36 37 38 39 |
# File 'lib/bsv/wallet/daemon.rb', line 31 def initialize(services:, pending_pushes: -> { [] }, stale_fetches: -> { [] }, pending_proofs: -> { [] }, interval: 30) @services = services @pending_pushes = pending_pushes @stale_fetches = stale_fetches @pending_proofs = pending_proofs @interval = interval @running = false end |
Instance Method Details
#run_cycle ⇒ Object
Execute one polling cycle. Public for testability.
58 59 60 61 62 63 64 65 |
# File 'lib/bsv/wallet/daemon.rb', line 58 def run_cycle push_pending fetch_stale fetch_proofs sleep @interval rescue StandardError => e BSV.logger&.error { "[Daemon] cycle error: #{e.class}: #{e.}" } end |
#running? ⇒ Boolean
Whether the daemon is currently running.
53 54 55 |
# File 'lib/bsv/wallet/daemon.rb', line 53 def running? @running end |
#start ⇒ Object
Start the polling loop. Blocks until stop is called.
42 43 44 45 |
# File 'lib/bsv/wallet/daemon.rb', line 42 def start @running = true run_cycle while @running end |
#stop ⇒ Object
Signal the loop to exit after the current cycle completes.
48 49 50 |
# File 'lib/bsv/wallet/daemon.rb', line 48 def stop @running = false end |