Exemplo n.º 1
0
        public async Task Stop()
        {
            _stopping = true;

            ICollection <JobHandle> pendingJobs = _registry.GetAll();

            foreach (var jobHandle in pendingJobs)
            {
                if (jobHandle.Status == JobStatus.Created || jobHandle.Status == JobStatus.Running)
                {
                    try
                    {
                        if (_log.IsDebugEnabled)
                        {
                            _log.DebugFormat("Cancelling job: {0}", jobHandle.JobId);
                        }

                        await jobHandle.Cancel().ConfigureAwait(false);

                        JobHandle removed;
                        _registry.TryRemoveJob(jobHandle.JobId, out removed);

                        await jobHandle.NotifyCanceled("Job Service Stopped").ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        if (_log.IsErrorEnabled)
                        {
                            _log.Error($"Failed to cancel job: {jobHandle.JobId:N}", ex);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task Stop()
        {
            _stopping = true;

            ICollection <JobHandle> pendingJobs = _registry.GetAll();

            foreach (var jobHandle in pendingJobs)
            {
                if (jobHandle.Status == JobStatus.Created || jobHandle.Status == JobStatus.Running)
                {
                    try
                    {
                        LogContext.Debug?.Log("Cancelling job: {JobId}", jobHandle.JobId);

                        await jobHandle.Cancel().ConfigureAwait(false);

                        _registry.TryRemoveJob(jobHandle.JobId, out _);

                        await jobHandle.NotifyCanceled("Job Service Stopped").ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        LogContext.Error?.Log(ex, "Cancel job faulted: {JobId}", jobHandle.JobId);
                    }
                }
            }
        }