npm.io
0.1.0 • Published 3d ago

@systemfsoftware/effect-daemon-spec

Licence
MIT
Version
0.1.0
Deps
0
Size
67 kB
Vulns
0
Weekly
0
Stars
1

@systemfsoftware/effect-daemon-spec

Supervise dynamic worker trees in Effect — restart policies, leader election, and health-gated retries built on top of Effect's supervision primitives.

Effect's built-in Supervisor tracks fibre lifecycles but doesn't give you daemon semantics. This library fills the gap: exponential backoff on restart, distributed leader election via Duration-based fencing, and poll-based health checks that gate restart decisions.

import { Daemon, RestartPolicy } from '@systemfsoftware/effect-daemon-spec'
import { Effect } from 'effect'

const pool = Daemon.supervised('worker-pool', {
  bootstrap: [worker, worker, worker],
  policy: RestartPolicy.exponential({
    minDelay: '100 millis',
    maxDelay: '10 seconds',
  }),
})

Effect.scoped(pool).pipe(Effect.runFork)

A leader-lock coordinator ensures only one node acts as the leader for a given key:

import { LeaderLock } from '@systemfsoftware/effect-daemon-spec'

const myLock = LeaderLock.make({
  key: 'daemon-leader',
  leaseDuration: '5 seconds',
  renewInterval: '1 second',
})

Install

pnpm add @systemfsoftware/effect-daemon-spec

effect is a peer dependency — you bring your own.

Keywords