I'm doing a Fire-and-Forget method invocation like this.
BackgroundJob.Enqueue(() => SendEmail(name));
I would like to pass the job id to the SendEmail() method and use it inside the method.
The easy way is to add
PerformContext
to the job method:. Hangfire Forum topic Use Hangfire job id in the code.
Change the SendEmail method to look like this...
public void SendEmail(string name, string jobId)
{
//Body of method
}
Change the Hangfire call to look like this...
BackgroundJob.Enqueue((string jobId) => SendEmail(name, jobId));
Unless, you're looking to run a job, and send an email one complete, then you might have to do the following...
var jobId = BackgroundJob.Enqueue(() => TaskToRun);
BackgroundJob.ContinueWith(jobId, () => SendEmail(name, jobId));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With