Call Hangfire Job (Recurring Job) from external API

3.1k views Asked by At

I have been using Hang-fire in our project but had a question, Can i call a hangfire Recurring Job from an API?

For Example: http://devmyproject.com/projectname/recurring is the url for Hangfire web application to get recurring job. Now from my webApi project i want to call this Url and invoke a Job to run. Is this Possible?

Thanks

2

There are 2 answers

2
rjustin On

Yes you can certainly perform hangfire functions by calling an API. Here is the function for creating a Hangfire job as listed on the front page of hangfire site.

RecurringJob.AddOrUpdate(
    () => Console.WriteLine("Recurring!"),
Cron.Daily);

The URL you call should be an endpoint which you can pass parameters to. Then if hangfire is set up correctly it should be like any other application.

0
Arjun A On

In The HangFire Project i added an end points to make it an API to get the Requests and then run the Hangfire job. I added Fire and Forget Job to run the HangFire job.