-1

Is there any way to expose Hangfire Job as Service? I wanted some of my hangfire jobs to be triggered from outside of hangfire project.

Vetrivel mp
  • 1,214
  • 1
  • 14
  • 29

1 Answers1

0

After some analysis we are able to achieve this. since it will be useful to someone i am sharing here.

  1. I am using .netcore razor pages in hangfire project.

  2. Create normal web api controller inside hangfire project. (.addmvc() function should be there in startup)

  3. Add endpoint inside api.

    [HttpGet("RecurringJob")]
     public void TriggerRecurringJob(string jobId)
     {
             RecurringJob.AddOrUpdate<IJobScheduler>(
                             JobId,
                             task => task.ScheduleAnyJob(),
                             "jobCron",
                             timeZone: TimeZone.Local);
    
          RecurringJob.Trigger(jobId);
     }
    
  4. Now you can run expose and consume as normal api inside hangfire project itself. If you require any authentication then you can implement filters.

Vetrivel mp
  • 1,214
  • 1
  • 14
  • 29