public string AddRecurJobSchedule <T>(T job, string cronExpression) { var id = Guid.NewGuid().ToString(); RecurringJob.AddOrUpdate( id, () => JobScheduleHandler.Trigger(job), cronExpression); using (var scope = Applibs.AutofacConfig.Container.BeginLifetimeScope()) { var jobName = job.GetType().Name; var repo = scope.Resolve <IJobScheduleRepository>(); var jobSchedule = new JobSchedule() { JobScheduleId = id, JobScheduleName = jobName, JobScheduleContent = JsonConvert.SerializeObject(job), CreateDateTimeStamp = TimeStampHelper.ToUtcTimeStamp(DateTime.Now) }; repo.Add(jobSchedule); Console.WriteLine($"{DateTime.Now}-JobScheduleService AddJobSchedule:{JsonConvert.SerializeObject(jobSchedule)}"); } return(id); }
public string AddJobSchedule <T>(T job, DateTime triggerDatetime) { var id = BackgroundJob.Schedule( () => JobScheduleHandler.Trigger(job), triggerDatetime); using (var scope = Applibs.AutofacConfig.Container.BeginLifetimeScope()) { var jobName = job.GetType().Name; var repo = scope.Resolve <IJobScheduleRepository>(); var jobSchedule = new JobSchedule() { JobScheduleId = id, JobScheduleName = jobName, JobScheduleContent = JsonConvert.SerializeObject(job), CreateDateTimeStamp = TimeStampHelper.ToUtcTimeStamp(DateTime.Now) }; repo.Add(jobSchedule); Console.WriteLine($"{DateTime.Now}-JobScheduleService AddJobSchedule:{JsonConvert.SerializeObject(jobSchedule)}"); } return(id); }