https://github.com/ahydrax/hangfire.atoms
Execute multiple jobs as a one atomic job.
https://github.com/ahydrax/hangfire.atoms
atoms hangfire
Last synced: 4 months ago
JSON representation
Execute multiple jobs as a one atomic job.
- Host: GitHub
- URL: https://github.com/ahydrax/hangfire.atoms
- Owner: ahydrax
- License: mit
- Created: 2018-09-10T23:25:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-30T03:24:52.000Z (about 1 year ago)
- Last Synced: 2026-01-17T04:58:13.214Z (5 months ago)
- Topics: atoms, hangfire
- Language: C#
- Homepage: https://www.nuget.org/packages/Hangfire.Atoms
- Size: 104 KB
- Stars: 23
- Watchers: 4
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hangfire.Atoms
[](https://www.nuget.org/packages/Hangfire.Atoms/)
Execute multiple jobs as a single atomic job.
## READ THIS BEFORE UPGRADE
If you're coming from version `<=0.3` you have to wait till your atomic jobs (in enqueued, scheduled, awaiting, etc. states) finishes as in version `0.4` data schema has been changed dramatically and this can lead to job state corruption.
This affects only existing users. New users have not to worry about anything.
## Requirements
* The storage you chosen must implement `JobStorageConnection` & `JobStorageTransaction`
* NET Standard 2.0 compatible project
## Setup
Install a package from Nuget. Then configure your server and dashboard like this:
```csharp
services.AddHangfire(configuration =>
{
configuration.UseStorage(yourStorage);
configuration.UseAtoms();
});
```
Or this:
```csharp
GlobalConfiguration.UseStorage(yourStorage);
GlobalConfiguration.UseAtoms();
```
You **must** setup Hangfire storage before calling `UseAtoms();`.
## Usage
Additional extension methods are added for `IBackgroundJobClient`.
### Atoms
```csharp
var client = new BackgroundJobClient();
// Enqueue
var atomId = client.Enqueue("atom-1", builder =>
{
for (var i = 0; i < 50; i++)
{
builder.Enqueue(() => DoWork());
}
});
// Continuations
var job1 = client.Enqueue(() => DoPrepare());
var atomId = client.ContinueWith(job1, "atom-2", builder =>
{
for (var i = 0; i < 50; i++)
{
builder.Enqueue(() => DoWork());
}
});
// Scheduling
var atomId = client.Schedule("atom-3", TimeSpan.FromSeconds(3), builder =>
{
for (var i = 0; i < 50; i++)
{
builder.Enqueue(() => DoWork());
}
});
// Atoms can be used as a common job which means you can continue them
client.ContinueWith(atomId, () => Done());
```
### Triggers
Triggers are event-like primitives. You can subscribe to it and set it manually whenever you need it.
```csharp
// Triggers
var triggerJobId = client.OnTriggerSet("trigger-1");
client.ContinueWith(triggerJobId, () => DoWork());
// Set trigger manually when you need it
client.Schedule(() => SetTrigger("trigger-1"), TimeSpan.FromSeconds(10));
```
## License
Authored by: Viktor Svyatokha (ahydrax)
This project is under MIT license. You can obtain the license copy [here](https://github.com/ahydrax/Hangfire.Atoms/blob/master/LICENSE).
This work is based on the work of Sergey Odinokov, author of Hangfire.