TickerNet docs Sponsored by Omniscient AI

TickerNet · using it

Remote workers

Run job code in separate processes, such as a service that owns the code and its dependencies, while one scheduler keeps the jobs, the schedule and the dashboard. The scheduler is the hub: workers connect to it directly with TickerNet.Worker. No hosted service is involved. Every API name, option and default on this page comes from src/TickerNet.Hub and src/TickerNet.Worker.

On this page
  1. How it works
  2. Set up the scheduler
  3. Set up a worker
  4. Name and schedule remote jobs
  5. What happens when
  6. Security
  7. Known limits
  8. Coming from TickerQ Hub
  9. Samples and decisions
→

How it works

Two packages. TickerNet.Hub goes in the scheduler, TickerNet.Worker in each app that runs job code.

overviewone worker node, one scheduler
worker app                                     scheduler app
TickerNet + TickerNet.Worker                   TickerNet + TickerNet.Hub (+ store, dashboard)

[TickerFunction("SendReport")]
AddTickerNetWorker(NodeName = "reports")
   │  opens one gRPC stream over HTTP/2  ────►  MapTickerNetHub()
   │  with signed tickernet-* headers           checks the headers before reading anything
   │  Hello: node, functions, HMAC  ─────────►  checks the Hello
   │  checks the hub's signature    ◄─────────  HelloAck, signed; registers SendReport@reports
   │                                            stores and schedules jobs as usual
   │                                            job SendReport@reports is due
   │                                ◄─────────  ExecuteFunction: one attempt, with the payload
   │  runs SendReport                           (waits)
   │  ExecutionResult  ──────────────────────►  records Done, Failed, Cancelled or Skipped;
   │                                            retries from the scheduler if retries are left
   │  stopping: Draining, finish runs ───────►  sends it no new runs
  • The worker dials out. It needs network access to the scheduler, but the scheduler never connects to the worker, so workers can sit behind NAT or in another cluster.
  • The scheduler stays in charge. Storage, polling, locking, retries, cancelling, status, history, job event logs, tracing and the dashboard all stay on the scheduler. A worker runs one attempt at a time for each run it is sent and reports back.
  • The scheduler's own job runner calls remote functions the same way it calls local ones, through a function delegate. For a remote function, that delegate sends the attempt to a worker and turns the result into the outcome the runner expects. Local and remote functions can live in the same scheduler.
01

Set up the scheduler

Reference TickerNet and TickerNet.Hub. Call AddTickerNetHub inside AddTickerNet, and MapTickerNetHub on the app.

Program.csscheduler, from samples/TickerNet.Sample.Hub
using Microsoft.AspNetCore.Server.Kestrel.Core;
using TickerNet.DependencyInjection;
using TickerNet.Hub;

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(kestrel =>
{
    kestrel.ListenLocalhost(5080);                                                   // dashboard and API
    kestrel.ListenLocalhost(5081, listen => listen.Protocols = HttpProtocols.Http2); // workers
});

builder.Services.AddTickerNet(options =>
{
    options.AddTickerNetHub(hub =>
    {
        // From your secret store or configuration, never from source code.
        hub.SharedSecret = builder.Configuration["TickerNet:SharedSecret"]!;
    });
});

var app = builder.Build();
app.UseTickerNet();
app.MapTickerNetHub();   // the endpoint workers connect to
app.Run();
  • HTTP/2. Workers speak gRPC, which needs HTTP/2. Over HTTPS, Kestrel's default endpoints offer HTTP/2 already. Without TLS, HTTP/2 (h2c) needs an endpoint of its own with Protocols = HttpProtocols.Http2, as above. Use HTTPS outside a trusted private network.
  • MapTickerNetHub() maps the gRPC service at /tickernet.worker.v1.WorkerHub/OpenWorkerStream and returns an IEndpointConventionBuilder, so you can add conventions such as .RequireHost(...). Calling it without AddTickerNetHub throws InvalidOperationException.
  • The store. The scheduler keeps a normal TickerNet store: EF Core, Redis, MongoDB, or in memory for trying it out.

TickerNetHubOptions

OptionDefaultWhat it does
SharedSecretnone, requiredThe secret every worker must prove it knows. At least 32 characters; AddTickerNetHub throws InvalidOperationException otherwise.
WorkerWaitTimeout30 secondsHow long a due run waits for a connected worker of its node that declared the function and isn't stopping. After that the run is recorded as Skipped with a "worker node offline" reason. A run that never reached a worker is sent to another within the same wait.
ExecutionTimeoutnull (no limit)Longest one attempt may take on a worker. When it passes, the scheduler sends a cancel to the worker and records a failure.
WorkerTimeout45 secondsA worker that sends nothing for this long is dropped and its connection closed. Workers send a heartbeat every 15 seconds by default.
SeedCronTickerstrueCreate or update cron jobs for worker functions that have a cron expression in [TickerFunction]. The hub never deletes them.
PauseCronTickersWhileOfflinetruePause a remote function's cron jobs while no connected worker that declares the function can take runs, and resume them when one can. When turned off, the hub clears any earlier pauses once at startup.
MaxMessageSize16 MBLargest message, in bytes, either side may send.
02

Set up a worker

Reference TickerNet, TickerNet.Worker and the source generator, write [TickerFunction] methods as usual, and call AddTickerNetWorker.

Program.csworker, from samples/TickerNet.Sample.HubWorker
using TickerNet.DependencyInjection;
using TickerNet.Utilities.Base;
using TickerNet.Worker;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddTickerNet(options => options.AddTickerNetWorker(worker =>
{
    worker.HubAddress = new Uri(builder.Configuration["TickerNet:HubAddress"]!);   // e.g. https://scheduler.internal:5001
    worker.SharedSecret = builder.Configuration["TickerNet:SharedSecret"]!;
    worker.NodeName = "reports";                                                  // the same for every replica
}));

var host = builder.Build();
host.UseTickerNet();
await host.RunAsync();

public class ReportJobs
{
    [TickerFunction("SendReport")]
    public Task SendReportAsync(TickerFunctionContext context, CancellationToken cancellationToken)
        => Task.CompletedTask;

    // Gets a cron job on the scheduler, paused while no "reports" worker is connected.
    [TickerFunction("NightlyCleanup", "0 3 * * *")]
    public Task NightlyCleanupAsync(TickerFunctionContext context, CancellationToken cancellationToken)
        => Task.CompletedTask;
}
  • Call UseTickerNet() on the worker too. It builds the function list the worker offers. A worker with no functions logs a warning when it connects.
  • Don't add a job store. A worker doesn't poll or store jobs: AddTickerNetWorker turns off the background services and cron seeding, and replaces the store with one that sends requests to the scheduler. Adding EF Core, Redis or MongoDB to a worker as well is not supported.
  • Connecting. The worker waits for the host to start, then connects and reconnects on its own, waiting 1 second and doubling up to MaxReconnectDelay. If the scheduler refuses it (wrong secret, clock off, bad node name), or the server can't sign its reply because it doesn't have the secret, the worker logs an error and retries at the longest delay. If the scheduler has no worker endpoint, it logs that app.MapTickerNetHub() is missing.
  • Plain HTTP. An http HubAddress that isn't loopback makes AddTickerNetWorker throw, unless you set AllowUnencryptedHttp for a trusted private network.
  • Stopping. When the host stops, the worker sends Draining, so the scheduler sends it no new runs, and rejects any run that still arrives. It lets the runs it has finish and report, then disconnects. Runs still going after ShutdownTimeout are cancelled. Keep ShutdownTimeout below the host's shutdown timeout, which is 30 seconds by default.

TickerNetWorkerOptions

OptionDefaultWhat it does
HubAddressnone; this or HubAddresses is requiredAbsolute http or https address of the scheduler's worker endpoint.
HubAddressesemptyWith several scheduler instances, the address of each one (worker.HubAddresses.Add(...)). The worker connects to all of them. Used together with HubAddress if both are set.
SharedSecretnone, requiredThe scheduler's SharedSecret. At least 32 characters.
NodeNamenone, requiredThe worker's node: 1 to 100 characters, without @ or whitespace. See naming.
MaxConcurrency0 (no limit)Most runs this worker executes at once. Each function's own maxConcurrency from [TickerFunction] also applies, per worker.
HeartbeatInterval15 secondsHow often the worker tells the scheduler it is alive. Keep it well under the scheduler's WorkerTimeout.
OperationTimeout30 secondsHow long the worker waits for the scheduler to answer a request to add, change or remove jobs, or to send a stored request.
MaxReconnectDelay30 secondsLongest wait between reconnect attempts.
ShutdownTimeout25 secondsOn shutdown, how long the worker waits for its runs to finish and report before it cancels them. Keep it below the host's shutdown timeout (30 seconds by default).
AllowUnencryptedHttpfalseAllow a plain http HubAddress on another machine. Without TLS the connection can be read and changed on the network, so only set it inside a trusted private network.
MaxMessageSize16 MBLargest message, in bytes, either side may send.
ConfigureChannelnullAn Action<GrpcChannelOptions> that changes the gRPC channel before it connects, for example to set an HttpHandler with a client certificate or a proxy.

Both option classes are checked when you call AddTickerNetHub or AddTickerNetWorker, which throw InvalidOperationException with the reason if a required value is missing or out of range.

03

Name and schedule remote jobs

A remote function is stored and scheduled as function@node.

  • function@node. When a worker of node reports connects with SendReport, the scheduler registers SendReport@reports. Names without @ are local functions that run in the scheduler's own process. Several nodes can offer a function with the same name. RemoteFunctionName in TickerNet.Utilities has helpers for the rule: IsRemote, Qualify, GetNodeName, GetFunctionName and IsValidNodeName.
  • Replicas share a node name. Workers with the same node name are replicas. Each run goes to one that declared the function and isn't stopping, preferring the one with the fewest runs in progress and rotating between equals. A node's function list is the union of what its workers have declared since the scheduler started, so during a rolling deploy a replica on another version never removes a function the others still offer, and runs of a new function go only to the replicas that have it.
  • Spell node names the same way everywhere. Routing a run to a worker ignores case, but the stored function name uses the spelling of the first worker of that node to connect, so SendReport@Reports and SendReport@reports are different jobs.
  • Local names with @. A local function whose own name contains @ is left alone: the hub never replaces it and never pauses its cron jobs.
  • Function names sent by a worker must be 1 to 200 characters without @, unique, and at most 10,000 per worker.

From the scheduler

Use the managers as for any job, with the remote name. The function must be known to the scheduler: a worker of that node has connected since the scheduler started.

schedulera remote time job
await timeTickers.AddAsync(new TimeTickerEntity
{
    Function = "SendReport@reports",
    ExecutionTime = DateTime.UtcNow.AddMinutes(5),
    Request = TickerHelper.CreateTickerRequest(new ReportRequest(42)),
    Retries = 2
});

From code on a worker

Inject ITimeTickerManager<TimeTickerEntity> or ICronTickerManager<CronTickerEntity> on the worker and use the worker's own function names. The worker adds its node name, including on chained child jobs, and the scheduler saves the job through its own managers, so validation, the dashboard and immediate dispatch work as usual. The job below is stored as SendReport@reports.

workerscheduling from a worker
await timeTickers.AddAsync(new TimeTickerEntity
{
    Function = "SendReport",               // stored on the scheduler as "SendReport@reports"
    ExecutionTime = DateTime.UtcNow.AddMinutes(5)
});

A worker may only touch its own node's jobs. The scheduler enforces this:

  • Add. Only function@itsnode jobs, children included. A job for another node's function, or for a local function, is refused. On added jobs the scheduler resets status, lock and history fields, so a worker can't add a job that looks done or locked.
  • Update. Only its own node's jobs, and only the schedule fields. For time jobs: Function (still on the same node), Description, ExecutionTime, Request, Retries, RetryIntervals and RunCondition. For cron jobs: Function, Description, Expression, Request, Retries, RetryIntervals and IsEnabled. Extra properties on your own entity subclasses aren't updated from workers.
  • Remove. Only its own node's jobs. A request that names another node's job is refused.
  • Read. Only the stored request of a run it is executing, which is what TickerRequestProvider.GetRequestAsync<T> needs. Reading or querying jobs otherwise isn't available on a worker; those store methods throw NotSupportedException. Query jobs on the scheduler.
  • Rate. The scheduler handles at most 8 of these requests from one worker at a time. Further messages from that worker wait until one finishes.
04

What happens when

Statuses are the usual TickerStatus values, recorded on the scheduler.

SituationWhat TickerNet does
A run of function@node is dueThe scheduler's job runner calls the function's delegate, which picks a connected worker of the node that declared the function and isn't stopping, and sends it one attempt, with the job's stored request. The worker runs the function in a new dependency injection scope and sends back the result. TickerRequestProvider.GetRequestAsync<T> on the worker reads the request that came with the run.
No worker of the node can take itNone is connected, or none of those connected declared the function or all are stopping. The run waits up to WorkerWaitTimeout for one that can. If none does, the run is Skipped with a "worker node offline" reason, and its retries are not used up.
A run never reached a workerThe connection closed before the run was sent, or the worker rejected it because it is stopping or doesn't have the function. The run goes to another worker of the node within WorkerWaitTimeout, without using a retry, and is skipped as above if none takes it.
Replicas declare different functionsThe node's function list is the union of what its workers declared, and each run goes only to a worker that declared that function. A replica on an older or newer version doesn't remove functions the others offer.
The function throws on the workerThe run is Failed. The exception type and message from the worker go into the job's exception details; on the scheduler they arrive as a RemoteExecutionException carrying the worker's stack trace.
The job has retriesThe scheduler runs the retry loop and waits RetryIntervals between attempts. Each attempt is sent on its own, so a retry can go to another replica. context.RetryCount on the worker says which attempt it is.
Someone cancels the runCancelling on the scheduler, from the dashboard or with TickerCancellationTokenManager.RequestTickerCancellationById, sends a cancel to the worker, which cancels the function's CancellationToken. The run is Cancelled. context.RequestCancellation() on the worker cancels it there.
The function skips itselfA TerminateExecutionException on the worker, for example from SkipIfAlreadyRunning(), records the status it carries, Skipped by default.
A run takes longer than ExecutionTimeoutThe scheduler stops waiting, sends a cancel to the worker and records a failure. Retries apply.
A worker stopsIt sends Draining, so it gets no new runs; runs that still reach it are rejected and go to another worker. It finishes its runs, reports them and disconnects. Runs still going after its ShutdownTimeout are cancelled when it disconnects, so the scheduler records them like a disconnect during a run, below.
The worker disconnects during a runThe scheduler records a failure ("disconnected before the run finished") and retries if retries are left, possibly on another replica. The worker cancels the runs it still has, so they don't run twice.
A worker goes quiet without disconnectingAfter WorkerTimeout without a message, the scheduler drops the worker. Its runs fail as above.
A worker function has a cron expressionWhen the worker connects, the scheduler creates or updates a cron job for function@node, as it does for its own [TickerFunction] cron functions. It never deletes one. While no connected worker that declares the function can take runs, its cron jobs are paused (IsSystemPaused), so no runs are created only to be skipped; they resume when one can. The dashboard marks a paused cron job with a Worker offline badge next to its function. Cron jobs you add yourself for a remote function are paused and resumed the same way. A seeded cron job whose function no worker declares any more stays paused; remove it from the dashboard if you no longer want it. A worker that connects with no functions changes nothing.
The scheduler restartsRemote functions are registered again as workers reconnect. For WorkerTimeout after it starts, the scheduler doesn't pause any cron job, giving workers time to reconnect; after that, cron jobs whose function no connected worker offers are paused. A run that comes due first still waits up to WorkerWaitTimeout for a worker. Cron seeding at startup no longer deletes seeded cron jobs for function@node, in any store.
The scheduler stopsThe hub sends each worker a Disconnect and closes its stream straight away, so it doesn't hold up shutdown. Runs in progress on the workers are cancelled because their connection closed, and the workers keep trying to reconnect until the scheduler is back.
You run several scheduler instancesRun AddTickerNetHub on every instance, with the same store and shared secret, and give each worker every instance's address in HubAddresses. The worker keeps a connection to each, so whichever instance picks up a due job can send it to a worker; jobs a worker adds go through any connected instance. Each address must reach one instance, not a load balancer in front of several: for example the per-pod DNS names of a Kubernetes StatefulSet behind a headless service.
All workers of a node stopThe node's functions stay registered until the scheduler restarts, so jobs can still be added for them, and due runs wait, then skip, as above.
05

Security

A worker can run code on the scheduler's schedule and add jobs, so treat the shared secret like any other credential.

  • Before the stream is read. The worker opens the stream with four request headers: tickernet-node, tickernet-nonce, tickernet-timestamp and tickernet-signature, a base64 HMAC-SHA256 over the node, nonce and timestamp. The scheduler checks that the timestamp is within 5 minutes, that the signature matches its SharedSecret, and that it hasn't seen the nonce, before it reads anything from the stream. A rejected worker is logged with its address.
  • Hello. The worker's first message must arrive within 10 seconds and repeat the node, nonce and timestamp from the headers. Its own HMAC also covers the worker and protocol versions, the worker's concurrency limit, and each function's name, cron expression, priority and concurrency limit, so the function list can't be changed on the way. The scheduler rejects control characters and over-long values in these fields.
  • Both sides prove the secret. The scheduler signs its HelloAck over the worker's nonce and the worker id it assigns. A worker refuses a server that can't, logging that it "didn't prove it knows the shared secret", so it never takes runs from a server pretending to be the scheduler.
  • A worker only touches its own node. It can add, change and remove only function@itsnode jobs, change only their schedule fields, and read only the request of a run it is executing. See Name and schedule remote jobs.
  • Replays. Nonces are kept in the scheduler's memory. A restarted scheduler forgets them, and the 5-minute window limits how long a captured call could be replayed after that.
  • Use TLS. The handshake proves who each side is, but doesn't encrypt anything. Use an https HubAddress; a plain http address to another machine needs AllowUnencryptedHttp, for trusted private networks only. For client certificates or a proxy, set ConfigureChannel on the worker.
  • Restrict the endpoint. MapTickerNetHub() returns a convention builder: add .RequireHost("workers.example.internal"), an authorization policy, or serve it on an internal port only.
  • Keep the secret out of code. Load it from your secret store or configuration on both sides. Use a long random value, for example from openssl rand -base64 48. To change it, update the scheduler and every worker together: workers with the old secret are refused until they restart with the new one.
  • Versions. This is worker protocol version 1. The scheduler refuses a worker that speaks another version, so run matching TickerNet versions.
06

Known limits

Known gaps in 1.0.0.

  • Several scheduler instances need every address. A worker that can't reach one of the instances misses that instance's runs, which wait, then are skipped. Workers don't discover instances on their own yet: list them in HubAddresses.
  • Workers can't read jobs. Queries and reads on a worker throw NotSupportedException; read jobs on the scheduler. A worker can read only the request of a run it is executing.
  • Seeded cron jobs aren't cleaned up. The hub never deletes a seeded cron job, so one for a function that was removed from the workers stays, paused, until you delete it from the dashboard.
  • New remote jobs need a known function. Right after the scheduler restarts, adding a job for function@node fails validation until a worker of that node has connected.
  • No log forwarding. Log output from a function goes to the worker's own logging, not to the dashboard.
  • SkipIfAlreadyRunning() only sees runs on the same worker that belong to the same cron job, not runs on other replicas.
07

Coming from TickerQ Hub

For apps that used TickerQ's remote executor and SDK at TickerNet's fork point.

TickerQTickerNet
TickerQ Hub, the hosted serviceNot supported. The scheduler is the hub, so nothing else is needed.
TickerQ.RemoteExecutor in the schedulerTickerNet.Hub: AddTickerNetHub and MapTickerNetHub.
TickerQ.SDK in the workerTickerNet.Worker: AddTickerNetWorker, with the scheduler's address and the shared secret set on the worker instead of a hub API key.
Jobs stored as function@nodeKept. They run on a TickerNet worker that uses the same node name.
CronTickerEntity.IsSystemPaused and its columnKept, with the same name and meaning, so the database needs no change.
SdkOfflineSkipExceptionStill works but is obsolete: it now derives from WorkerOfflineException, the new name, and both record a run as Skipped.
TickerFunctionProvider hooks: FunctionNodeResolver, ResolveNodeName, ReplaceFunctions, ReplaceRequestInfo, MergeRemoteFunctions, MergeRemoteRequestInfoKept. TickerNet.Hub uses MergeRemoteFunctions and MergeRemoteRequestInfo.
The SDK ran the retry loop and reported each statusThe scheduler runs retries and records every status; the worker runs one attempt per message.
The worker-stream protocolTickerNet's worker.proto keeps the message shapes and field numbers of TickerQ's worker stream and reserves the parts it doesn't use. It is not wire-compatible: the gRPC package and service are renamed, and TickerQ.SDK only connects through TickerQ Hub. Replace the SDK with TickerNet.Worker.
Per-run log forwarding to the hub's dashboardNot available. See limits.

The rest of the move, such as package IDs and namespaces, is in Migrating from TickerQ.

↓

Samples and decisions

  • Samples. samples/TickerNet.Sample.Hub is a scheduler with the dashboard on port 5080 and the worker endpoint on port 5081. samples/TickerNet.Sample.HubWorker is a worker for node reports. Set the same TickerNet:SharedSecret for both, for example through the TickerNet__SharedSecret environment variable, run both, then post to http://localhost:5080/send-report.
  • Tests. tests/TickerNet.Hub.Tests runs a real scheduler and workers on a local port.
  • Decisions. ADR 0009 records this design. ADR 0005 records why the TickerQ Hub clients were removed, and ADR 0010 the TickerQ names TickerNet still accepts.