.NET LocalJob
Background
This is a counterpart to SingletonJob where the job runs on every instance of your app. It's much simpler, since there's no Redis, no database, no coordination, and none of the trouble that comes with them.
You can find the package here:
https://github.com/haiilong/LocalJob
Why this exists
Some background work belongs to the process, not to the deployment: flushing a local metrics buffer, trimming this pod's temp directory, pinging a keep-alive, draining an in-memory queue.
You can already do this with Quartz or a plain .NET background service, but I wanted a few more things:
- Easier to create new jobs (Auto-discovery, templates, etc.)
- Easy to configure (polling interval, isEnabled?, ExecutionTimeout, etc.)
- Features that are not well supported today:
- Overlap protection
- Misfire handling
- Graceful shutdown
- Error handling that doesn't kill the loop
- Per-job Configuration
- RunOnStartup (for IntervalJob)
- Jitter (so that jobs don't hit your DB at the same time)
Take a look at the README and the sample project. It's easy to use and powerful enough.
Differences from SingletonJob
- No Redis, leader election, or anything related, so it's a lot simpler while keeping the same API shape
- Per-job settings live on the job class, not in
Program.cs. OverrideConfigureJobOptions; it receives the job's private copy of the options and runs last, afterappsettings.json. Since LocalJob is all in-process, the job class is the natural home for its config, while a lot of SingletonJob's configuration feels more like an operations concern - With no name-keyed config, an
IOptionsFactory<LocalJobOptions>constructor parameter would be overkill, so it takesIOptions<>instead.