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); }
public void AddTest() { var addResult = this.repo.Add(new JobSchedule() { JobScheduleId = Guid.NewGuid().ToString(), JobScheduleName = "Test", JobScheduleContent = "TestContent", CreateDateTimeStamp = TimeStampHelper.ToUtcTimeStamp(DateTime.Now) }); Assert.IsTrue(addResult); }