Beispiel #1
0
        public async Task <IActionResult> Update(string jobId, [FromBody] Job value)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(jobId))
                {
                    return(new JsonResult(new ApiResult(ApiResult.Error, "Id is empty/null")));
                }

                if (!await _store.CheckJobExists(jobId))
                {
                    return(new JsonResult(new ApiResult(ApiResult.Error, $"Job {jobId} not exists")));
                }

                var qzJob   = value.ToQuartzJob();
                var trigger = TriggerFactory.Create(value.Trigger, jobId, value.Properties);

                // TODO: need test if need delete qzJob firstly?
                value.Id = jobId;
                await _store.UpdateJob(value);

                await _scheduler.UnscheduleJob(new TriggerKey(jobId));

                await _scheduler.ScheduleJob(qzJob, trigger);

                return(new JsonResult(new ApiResult(ApiResult.SuccessCode, "success")));
            }

            return(new JsonResult(new ApiResult(ApiResult.ModelNotValid, GetModelStateErrorMsg())));
        }
Beispiel #2
0
        public async Task <IActionResult> Trigger(string jobId)
        {
            if (string.IsNullOrWhiteSpace(jobId))
            {
                return(new JsonResult(new ApiResult(ApiResult.Error, "Id is empty/null")));
            }

            if (!await _store.CheckJobExists(jobId))
            {
                return(new JsonResult(new ApiResult(ApiResult.Error, $"Job {jobId} not exists")));
            }

            await _scheduler.TriggerJob(new JobKey(jobId));

            _logger.LogInformation($"Trigger job {jobId} success");
            return(new JsonResult(new ApiResult(ApiResult.SuccessCode, "success")));
        }