| 1 | package daemon |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/FelineStateMachine/tinyrelay/internal/work" |
| 7 | ) |
| 8 | |
| 9 | // workRunner captures the tenant-wide queue composition before a worker |
| 10 | // goroutine starts. Feature services contribute handlers; their jobs share |
| 11 | // the same admission gate, observation and worker lifetime. |
| 12 | func (t *Tenant) workRunner() func(context.Context) error { |
| 13 | handlers := t.replication.Handlers() |
| 14 | for kind, handler := range t.workHandlers() { |
| 15 | handlers[kind] = handler |
| 16 | } |
| 17 | for kind, handler := range handlers { |
| 18 | handlers[kind] = t.guardWork(handler) |
| 19 | } |
| 20 | queue := t.replication.Queue() |
| 21 | options := work.PoolOptions{ |
| 22 | Worker: work.WorkerOptions{Observe: t.app.telemetry.ObserveWork}, |
| 23 | } |
| 24 | return func(ctx context.Context) error { |
| 25 | return work.RunPool(ctx, queue, handlers, options) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // runWork composes a fresh runner for tests and explicit worker restarts. |
| 30 | func (t *Tenant) runWork(ctx context.Context) error { |
| 31 | return t.workRunner()(ctx) |
| 32 | } |