示例#1
0
        public async Task Consume(ConsumeContext <CancelJob> context)
        {
            if (!_registry.TryGetJob(context.Message.JobId, out var jobHandle))
            {
                throw new JobNotFoundException($"The JobId {context.Message.JobId} was not found.");
            }

            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);
        }
示例#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);
                    }
                }
            }
        }
示例#3
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);
                        }
                    }
                }
            }
        }
示例#4
0
        public async Task Consume(ConsumeContext <CancelJob> context)
        {
            JobHandle jobHandle;

            if (!_registry.TryGetJob(context.Message.JobId, out jobHandle))
            {
                throw new JobNotFoundException($"The JobId {context.Message.JobId} was not found.");
            }

            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);
        }