コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }