Beispiel #1
0
        public async Task <IActionResult> PauseTaskAsync(PauseTaskRequest request)
        {
            var job = await _jobInfoStore.GetAsync(request.Id);

            if (job == null)
            {
                return(Json(new
                {
                    code = -1,
                    msg = "job不存在"
                }));
            }
            var scheduler = await _jobSchedularFactory.GetScheduler();

            var jk = JobKey.Create(job.TaskName, job.GroupName);
            await scheduler.PauseJob(jk);

            job.Status = EnumJobStates.Pause;
            await _jobInfoStore.UpdateAsync(job);

            await _jobLogStore.RecordAsync(jk, new JobLogModel
            {
                Time       = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}",
                RunSeconds = 0,
                State      = EnumJobStates.Pause,
                Message    = "暂停指令发送成功"
            });
        /// <inheritdoc />
        public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException,
                                   CancellationToken cancellationToken = new CancellationToken())
        {
            var  job          = context.JobDetail.Key;
            bool hasException = jobException != null;

            _jobLogStore.RecordAsync(job, new JobLogModel
            {
                Time       = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}",
                RunSeconds = context.JobRunTime.Seconds,
                State      = hasException ? EnumJobStates.Exception : EnumJobStates.Normal,
                Message    = jobException?.Message
            });