hangfire - RecurringJob - call Method in Controller
Hey,
I'm stuck on a issue here.
I'm trying to run a RecurringJob every night, and a need Hangfire to run a Method from a controller.
I Have this that should call the methoder in "SyncClubs"
public class ScheduleHangfireJobs
{
public void Sync()
{
RecurringJob.AddOrUpdate("Sync", () => SyncClubs(null), Cron.Daily(01, 00));
}
public void SyncClubs(PerformContext context)
{
//here should my method from the controller run.
ImportClubsController.ClubSync();
}
}
But when this run It fails on running the task from hangfire
System.NullReferenceException: Object reference not set to an instance of an object.
Is ther esomething i'm missing or are doing wrong ?
If I remove ImportClubsController.ClubSync(); and just add a context.WriteLine("Normal text!");
Then it works fine...
It looks like something to do with initializing the controller from your scheduler method. Not sure how your controller looks, as controller is also just a class you might consider using like new ImportClubsController.ClubSync();.
In general controllers are not to be use as business logic. Suggestion is to use it to maintain relation between view and business layer. You can move ClubSync method to different class file rather than in controller and see if it works.
hangfire - RecurringJob - call Method in Controller
Hey,
I'm stuck on a issue here.
I'm trying to run a RecurringJob every night, and a need Hangfire to run a Method from a controller.
I Have this that should call the methoder in "SyncClubs"
But when this run It fails on running the task from hangfire
Is ther esomething i'm missing or are doing wrong ? If I remove ImportClubsController.ClubSync(); and just add a
context.WriteLine("Normal text!");
Then it works fine...Hi Thomas,
It looks like something to do with initializing the controller from your scheduler method. Not sure how your controller looks, as controller is also just a class you might consider using like
new ImportClubsController.ClubSync();
.In general controllers are not to be use as business logic. Suggestion is to use it to maintain relation between view and business layer. You can move ClubSync method to different class file rather than in controller and see if it works.
Thanks
is working on a reply...