Ideas, job substitution, job migrations, job priority, job depend on

hi,
i got these crazy ideas but i think it is great for some use cases.

job substitution

let us say that you have the following simple job

public class SimpleJob{
 public void SayHello(){
   console.write("hello");    
   }
}

then later i update the above to

 public class SimpleJob{
     public void SayHello(string name){
         console.write("hello")+ name;   
       }
    }

it would be awesome if Hangfire can detect the new changes and any waiting jobs in the queue will be updated with the new code.

maybe it is already how hangfire works, i am not that smart :smile:

another idea is job migration

sometimes you don’t want to cancel jobs in queue but like above your code has changed or you completely created new class, so if we can add for example a migration attribute to the job, this way any jobs in the queue will smartly execute the new code.

another idea is job priority for individual jobs and groups.

sometimes you want to register a user, and you have 3 steps, first add to DB, secondly provision user, thirdly send an email. ofcourse you can put all these steps in one code, but separation is good, so we can split the above into 3 jobs and execute them by order, the benefit is for example, the adding user to db job succeeded, but provisioning failed, no problem Hangfire will only retry the second job. but if all this was in one job, hangfire will retry everything, or we have to make code checkups manually.

depend on

now this is cool, we add depend on attribute, and hangfire will keep this job in queue until the job it depends on get executed, if the the dependent on job is not executed, hangfire will keep this job in queue with some hint like “waiting for job #23232323 to be executed”.

job substitution
another idea is job migration

You can always call the new method from the old one. Job migrations do not make it easier enough to be implemented.

another idea is job priority for individual jobs and groups.
depend on

Some kind of very simple workflows will be implemented in future, but now you should emit one job from another or use other products, like Workflow Foundation or NServiceBus.

thank you for the advice man, i will dig into it.

Was something like the suggested “depend on” feature already implemented in Hangfire by now?

You can use the ContinueWith method to implement something like the depend on feature, just inverting the order. Basically, you create the initial job and then set the next job that will be executed after the first one is completed successfully.

var firstJobId = BackgroundJob.Enqueue(() => Console.WriteLine("First Job")); BackgroundJob.ContinueWith(firstJobId , () => Console.WriteLine("Second Job"));

1 Like