Coder Social home page Coder Social logo

hangfire.atoms's Introduction

Hangfire.Atoms

NuGet

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:

services.AddHangfire(configuration =>
    {
        configuration.UseStorage(yourStorage);
        configuration.UseAtoms();
    });

Or this:

GlobalConfiguration.UseStorage(yourStorage);
GlobalConfiguration.UseAtoms();

You must setup Hangfire storage before calling UseAtoms();.

Usage

Additional extension methods are added for IBackgroundJobClient.

Atoms

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.

// 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.

This work is based on the work of Sergey Odinokov, author of Hangfire. http://hangfire.io/

hangfire.atoms's People

Contributors

0xced avatar ahydrax avatar iamandymcinnes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hangfire.atoms's Issues

Async job support in AtomBuilder

Hi

I just wondered if there are any plans for async support within the atom job builder like we get in hangfire with BackgroundJob?

            var client = new BackgroundJobClient(JobStorage.Current);

            var atomId = client.Enqueue("atomjob", builder =>
             {
                 for (var i = 0; i < 50; i++)
                 {
                     builder.Enqueue(() => AsyncJob()); // Doesn't support async jobs
                     BackgroundJob.Enqueue(() => AsyncJob()); // Does support async jobs
                 }
             });

            client.ContinueJobWith(atomId, () => Done());

Many thanks

Andy

Test case 7 from test suite is failing

I was working on extending the test suite to cover my changes in my latest pull request and I noticed something regarding test case 7 and I was wondering if this is expected.

Reproducible steps:

  1. Install Redis e.g. run it via Docker docker run --name ix-redis -p 6379:6379 -d redis
  2. Get the latest master from the repository
  3. If needed, change downgrade the TargetFramework version to netcoreapp2.2
  4. If needed, add the following to appsettings.json when port 5000 is already in use on your system:
  "Kestrel": {
    "EndPoints": {
      "Http": {
        "Url": "http://0.0.0.0:5002"
      }
    }
  }
  1. Run the application
  2. In the Hangfire Dashboard trigger recurring job Atom test-7
  3. Wait for the job to start being processed
  4. Notice that the job gets stuck at 75% when you go to the Atoms running-section of the Jobs-page
  5. Notice that there is still an awaiting job

(full disclosure, I have the if needed steps as this was required on my work notebook)

I was wondering if this is correct behaviour or should the awaited task have been ran?

Typed enqueue, Enqueue<T>

I am wondering whether support for typed jobs could be added?
In Hangfire itself you can queue jobs via `Enqueue(task => task.Blah());

I am not sure if I can just add the necessary methods mysel or that your code needs changes to support these generics methods. I will experience with it.

Add queue selection support

jobClient.Enqueue("test", builder =>
{
	for (int i = 0; i < 10; i++)
	{
                // here
		builder.Enqueue<ITestJobs>(t => t.TestMethod(), "queue");
	}
// and/or here
}, "queue");

AtomBuilder.cs
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.