TickerNet docs Sponsored by Omniscient AI

ADR 0009 · Code and packages

Run jobs on remote workers through a self-hosted hub

Two new packages let job code run in separate worker processes with no hosted service: TickerNet.Hub turns the scheduler into the hub, and TickerNet.Worker connects to it. Workers and hub prove a shared secret to each other, a worker only touches its own node's jobs, and the scheduler sends one attempt at a time and keeps retries, status and history. The hooks TickerQ's remote executor used keep working.

Status
Amended 2026-11-23: workers can connect to several scheduler instances (HubAddresses), so one instance no longer has to run the hub alone; the hub waits WorkerTimeout after it starts before pausing cron jobs; the dashboard shows the pause.
Decided
2026-11-23
Affects
src/TickerNet.Hub, src/TickerNet.Worker, src/TickerNet.Utilities, src/TickerNet (including TickerNetDispatcher), the four stores, tests/TickerNet.Hub.Tests, samples/
01

Context

ADR 0005 removed TickerQ.SDK, TickerQ.RemoteExecutor and the Node SDK, which connect to TickerQ Hub, a hosted service with its own terms. That left TickerNet with no way to run job code outside the scheduler's process, and with public hooks for remote execution in src/: SdkOfflineSkipException, the TickerFunctionProvider merge and resolver members, and the CronTickerEntity.IsSystemPaused column.

Before the repository went public, the maintainer asked for remote execution that TickerNet owns, and for the TickerQ Hub hooks to stay backward compatible while TickerNet gets its own names for them.

At the fork point (3acd0f31), TickerQ's design worked like this. The SDK registered its functions with TickerQ Hub, got the scheduler's address and a shared secret from it, and opened a gRPC worker stream to the scheduler. The scheduler sent each run down that stream. The SDK ran the retry loop and reported each status change back over the stream. The hub endpoints were fixed in code.

02

Decision

  • Two packages. TickerNet.Hub (AddTickerNetHub, MapTickerNetHub, TickerNetHubOptions, RemoteExecutionException) runs in the scheduler. TickerNet.Worker (AddTickerNetWorker, TickerNetWorkerOptions) runs in each worker app. The scheduler is the hub; nothing else is deployed.
  • One stream per worker. The worker opens a bidirectional gRPC stream over HTTP/2 to the scheduler, defined in src/TickerNet.Hub/Protos/worker.proto (package tickernet.worker.v1, service WorkerHub, protocol version 1). It keeps the message shapes and field numbers of TickerQ's worker stream at the fork point and reserves the field numbers of parts TickerNet doesn't use: the hub API key, hosted-hub ids, resync and remove-function commands, status updates from the worker, and log lines. It adds a Draining message, a signature on HelloAck and a rejected flag on ExecutionResult. The worker needs only outbound access.
  • Authentication before anything is read. Scheduler and workers share a secret of at least 32 characters. The worker opens the stream with the headers tickernet-node, tickernet-nonce, tickernet-timestamp and tickernet-signature, a base64 HMAC-SHA256 over the node, nonce and timestamp. The hub checks freshness (5 minutes), the HMAC and the nonce (HelloReplayGuard, in memory) before it reads the stream. The Hello must then arrive within 10 seconds and match the headers. Its own HMAC covers the worker and protocol versions, the worker's concurrency limit and each function's name, cron expression, priority and concurrency limit. The hub rejects control characters and over-long values in signed fields. Signing and checking live in HelloSignature, compiled into both packages.
  • The hub proves the secret too. The hub signs its HelloAck over the worker's nonce and the worker id. A worker refuses a server that can't, so it never takes runs from a server that doesn't have the secret. A plain http hub address on another machine is refused at startup unless AllowUnencryptedHttp is set.
  • function@node, as a union. Remote functions are stored and scheduled as function@node, the rule TickerQ already used, now documented in RemoteFunctionName in TickerNet.Utilities. RemoteFunctionCatalog publishes each node's functions into TickerFunctionProvider with MergeRemoteFunctions and MergeRemoteRequestInfo. A node's list is the union of what its workers declared since the hub started, so a replica on another version never removes functions. A worker with no functions changes nothing. Functions stay registered after their workers disconnect. The catalog replaces only names it published, so a local function whose name contains @ is left alone.
  • One attempt per dispatch; the scheduler keeps the rest. The scheduler's own job runner, TickerExecutionTaskHandler, runs remote functions through a delegate from RemoteDispatch. The delegate picks a worker of the node that declared the function and isn't draining, preferring the one with the fewest runs in progress, and waits up to WorkerWaitTimeout if there is none. It sends one attempt with the stored request and turns the result into the outcome the runner expects: success; TaskCanceledException for a cancel; TerminateExecutionException for a skip; WorkerOfflineException when no worker takes the run, which records Skipped; RemoteExecutionException for a failure, a timeout or a disconnect during the run. A run that never reached a worker (the connection closed first, or the worker rejected it) goes to another worker within the same wait, without using a retry. Retries, cancelling, status, history, logs, tracing and the dashboard stay on the scheduler. This differs from TickerQ's design, where the SDK ran the retry loop and reported each status.
  • A worker only touches its own node. It can add, update and remove only function@itsnode jobs, children included. The hub resets status, lock and history fields on added jobs. Updates change only the schedule fields: for time jobs Function (same node), Description, ExecutionTime, Request, Retries, RetryIntervals and RunCondition; for cron jobs Function, Description, Expression, Request, Retries, RetryIntervals and IsEnabled. A worker can read only the stored request of a run it is executing. The hub handles at most 8 requests from one worker at a time. The hub saves accepted changes through its managers, with the host's lifetime rather than the worker's connection.
  • After a restart. HubTaskHandler wraps the job runner and gives a function@node run that has no delegate yet the dispatch delegate for its node, so it waits for a worker instead of being skipped at once.
  • Liveness and shutdown. Workers send a heartbeat every 15 seconds by default. WorkerLivenessMonitor drops a worker that sends nothing within WorkerTimeout (45 seconds), and its outstanding runs fail. A stopping worker sends Draining, rejects new runs, finishes and reports the runs it has, then disconnects; it cancels runs still going after ShutdownTimeout (25 seconds, under the host's 30-second default). When the scheduler stops, the hub sends each worker Disconnect and closes its stream at once instead of holding shutdown open.
  • Cron jobs. RemoteCronSeeder creates and updates cron jobs for worker functions with a cron expression through MigrateDefinedCronTickers, and never deletes one. WorkerPauseMonitor sets IsSystemPaused on remote cron jobs while no connected worker that declares the function can take runs, so a seeded cron job whose function no worker declares stays paused until someone removes it. Local functions are never paused. With PauseCronTickersWhileOffline off, the monitor clears earlier pauses once at startup. Seeding and pausing share a lock (CronWriteGate), so neither overwrites the other. Cron seeding at startup no longer deletes seeded cron jobs for function@node in the in-memory, EF Core, MongoDB and Redis stores.
  • The worker side. AddTickerNetWorker turns off the background services and cron seeding. WorkerClient keeps the stream open, reconnects with backoff, runs functions within the worker-wide and per-function concurrency limits, honours cancels, rejects runs of functions it doesn't offer, and drains on shutdown. RemotePersistenceProvider sends add, update and remove requests to the scheduler, and throws NotSupportedException for reads and queries.
  • Jobs dispatched straight away run with the host's lifetime. TickerNetDispatcher no longer passes the caller's CancellationToken to the jobs it dispatches at once, for example a time job added for now with AddAsync. They use the host's stopping token. A worker's connection, or an HTTP request, ending could otherwise cancel a job it had just added, or leave it InProgress.
  • The old hooks keep working. SdkOfflineSkipException is kept as an obsolete subclass of the new WorkerOfflineException, and the job runner handles both. The TickerFunctionProvider hooks, IsSystemPaused and the internal Retries and RetryIntervals on TickerFunctionContext are kept, with comments that describe TickerNet's hub.
03

Alternatives considered

  • Restore the TickerQ Hub clients under TickerNet names, still connecting to TickerQ Hub. Rejected: they depend on a paid hosted service with its own terms, which TickerNet doesn't control and whose protocol can change at any time, and its endpoints are fixed in the client code.
  • Keep only the hooks, or remove them under a new ADR, with no remote execution. Rejected by the maintainer, who asked for TickerNet's own remote execution and compatibility with existing TickerQ Hub hooks and data.
  • Delete seeded cron jobs a node no longer declares. The first version did this. Rejected: a replica on another version, or one started without its functions, would delete cron jobs, and their history, that other replicas still serve. They are paused instead.
  • Keep TickerQ's split, where the worker runs the retry loop and reports each status. Not chosen. With one attempt per dispatch, retries, cancelling, status and tracing have a single code path on the scheduler, a retry can go to another replica, and two processes never write the same job's status.
04

Consequences

  • Job code can run in separate processes, behind NAT or in another cluster, with the scheduler as the only server. The Remote workers guide covers set-up and behaviour.
  • New public API: the two packages, plus RemoteFunctionName and WorkerOfflineException in TickerNet.Utilities. SdkOfflineSkipException is obsolete.
  • New dependencies: Grpc.AspNetCore.Server in the hub, Grpc.Net.Client in the worker, Google.Protobuf in both, and Grpc.Tools at build time. The scheduler must accept HTTP/2.
  • Anyone with the shared secret can connect as any node: take that node's runs, with their requests, report their results, and change that node's jobs. They can't touch local jobs. Without TLS the traffic can be read and changed, which is why plain HTTP to another machine needs AllowUnencryptedHttp.
  • Rolling deploys are safe: draining workers finish their runs, runs that never reached a worker go to another one without using a retry, and replicas on different versions don't remove each other's functions or cron jobs.
  • Seeded cron jobs are never deleted by the hub. One for a function no worker declares any more stays paused until someone removes it from the dashboard.
  • Behaviour change in the core, for all apps: jobs dispatched straight away no longer run with the caller's CancellationToken, but with the host's stopping token. TickerQ, and TickerNet before this change, used the caller's token. Code that relied on cancelling such a job through that token must use TickerCancellationTokenManager.RequestTickerCancellationById. The migration guide notes it.
  • Extra properties on custom entity subclasses can't be changed from workers; change them on the scheduler.
  • TickerQ.SDK workers can't connect: the gRPC package and service names differ, the authentication is new, and the SDK only connects through TickerQ Hub. Workers move to TickerNet.Worker. Jobs stored as function@node carry over.
  • Known limits (still true in 1.0.0): with several scheduler instances every worker must list each instance's address, workers can't read jobs other than their current runs' requests, there is no per-run log forwarding to the dashboard, and SkipIfAlreadyRunning() only sees runs on the same worker.
  • Rule for later changes to worker.proto: never reuse a field number, reserve the numbers of removed fields, and raise HelloSignature.ProtocolVersion for an incompatible change.
  • TickerNet.Utilities and TickerNet expose internals to TickerNet.Hub, TickerNet.Worker and TickerNet.Hub.Tests.
05

Where it lives

  • src/TickerNet.Hub/: Protos/worker.proto, Protocol/HelloSignature.cs, TickerNetHubServiceExtensions.cs, TickerNetHubOptions.cs, RemoteExecutionException.cs, and Internal/ (WorkerStreamService.cs, WorkerConnection.cs, WorkerRegistry.cs, RemoteDispatch.cs, RemoteFunctionCatalog.cs, RemoteCronSeeder.cs (with CronWriteGate), RemotePayloadLoader.cs, HubTaskHandler.cs, HelloReplayGuard.cs, WorkerMonitors.cs)
  • src/TickerNet.Worker/: TickerNetWorkerServiceExtensions.cs, TickerNetWorkerOptions.cs, and Internal/ (WorkerClient.cs, RemotePersistenceProvider.cs, FunctionManifest.cs)
  • src/TickerNet.Utilities/RemoteFunctionName.cs, Exceptions/WorkerOfflineException.cs, Exceptions/SdkOfflineSkipException.cs, TickerFunctionProvider.cs, Entities/CronTickerEntity.cs
  • src/TickerNet/Src/TickerExecutionTaskHandler.cs and src/TickerNet/Src/Dispatcher/TickerNetDispatcher.cs
  • MigrateDefinedCronTickers in src/TickerNet/Src/Provider/TickerInMemoryPersistenceProvider.cs, src/TickerNet.EntityFrameworkCore/Infrastructure/BasePersistenceProvider.cs, src/TickerNet.MongoDB/Infrastructure/TickerMongoPersistenceProvider.cs and src/TickerNet.Caching.StackExchangeRedis/Infrastructure/BaseRedisPersistenceProvider.cs
  • tests/TickerNet.Hub.Tests/ (including HubSafetyTests.cs), tests/TickerNet.Tests/TickerNetDispatcherExtendedTests.cs, samples/TickerNet.Sample.Hub, samples/TickerNet.Sample.HubWorker
  • site/remote-workers.html
06

Sources

  • 7a56abd Backward compatibility with TickerQ, and a self-hosted hub for remote workers
  • 302fc65 Remove TickerQ Hub, upstream CI, CLA and caches
  • hub/ at 3acd0f31, TickerQ's remote executor and SDK at the fork point, MIT OR Apache-2.0