I am working on .Net Core 8 and HangFire 1.8.12 solution to run few recurring jobs. I have below code for interface
public interface IDatabaseMgtJobs
{
Task<int> BackupMyDatabase();
}
and I have implemented this interface and added required DI code to startup class.
I need to schedule this method to run on daily basis and I have added below code to setup recurring job using Hangfire jobs
RecurringJob.AddOrUpdate<IDatabaseMgtJobs>("backupMainDB", (Expression<Action<IDatabaseMgtJobs>>)(mgt => mgt.BackupMyDatabase()), cronexp, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"), "database");
with this code, I am able to place a job to Hangfire server but when its time to run the job its failing with below exception.
Hangfire.Common.JobLoadException: Could not load the job. See inner exception for the details.
—> System.InvalidOperationException: The type MIS.Interface.Database.IDatabaseMgtJobs
does not contain a method with signature BackupMyDatabase()
at Hangfire.Storage.InvocationData.DeserializeJob() in C:projectshangfire-525srcHangfire.CoreStorageInvocationData.cs:line 109
— End of inner exception stack trace —
at Hangfire.Storage.InvocationData.DeserializeJob() in C:projectshangfire-525srcHangfire.CoreStorageInvocationData.cs:line 120
at Hangfire.RecurringJobExtensions.TriggerRecurringJob(IBackgroundJobFactory factory, JobStorage storage, IStorageConnection connection, IProfiler profiler, RecurringJobEntity recurringJob, DateTime now) in C:projectshangfire-525srcHangfire.CoreRecurringJobExtensions.cs:line 115
at Hangfire.Server.RecurringJobScheduler.ScheduleRecurringJob(BackgroundProcessContext context, IStorageConnection connection, String recurringJobId, RecurringJobEntity recurringJob, DateTime now) in C:projectshangfire-525srcHangfire.CoreServerRecurringJobScheduler.cs:line 333
I am bit familier with HangFire Jobs, but not sure this time whats wrong with this code. Any suggestions ? thanks in advance !