コード例 #1
0
        public async Task ScheduleJobAsync(string jobId, JobDataModel jobData)
        {
            if (!SchedulerClientConfig.Version.Equals(jobData.SdkVersion))
            {
                throw new ApiValidationException("Invalid SDK version");
            }

            invalidatedEvent.WaitOne();

            var jobKey = JobKey.Create(jobId);

            using (await jobLockProvider.AcquireAsync(jobKey))
            {
                if (await scheduler.CheckJobExistsAsync(jobKey))
                {
                    var existingJobDetail = await scheduler.GetJobDetailAsync(jobKey);

                    if (jobData.GetDataHashCode().Equals(existingJobDetail.GetDataHashCode()))
                    {
                        Log.Debug("{jobId} job is up to date", jobId);
                        return;
                    }

                    Log.Debug("{jobId} job will be updated", jobId);

                    await scheduler.DeleteJobAsync(jobKey);

                    Log.Information("{jobId} job was deleted", jobKey.Name);
                }

                var newJobDetail = JobDetailFactory.Create(jobKey, jobData);
                await scheduler.CreateJobAsync(newJobDetail);

                Log.Information("{jobId} job was created", jobId);

                var newTrigger      = TriggerFactory.Create(jobKey, jobData);
                var firstFireMoment = await scheduler.CreateTriggerAsync(newTrigger);

                Log.Information($"{{jobId}} job was scheduled (next execution: {firstFireMoment})", jobId);
            }
        }