Exemplo n.º 1
0
 private void DetachJob(TaskJob job)
 {
     if (!_startedJobs.TryRemove(job.TaskId, out TaskJob removed))
     {
         throw new InvalidOperationException();
     }
     removed.Dispose();
 }
Exemplo n.º 2
0
        async Task IJobExecutorContext.OnDefferJob(TaskJob job)
        {
            DetachJob(job);

            logger.LogInformation($"Task {job.TaskId} deffered.");

            await taskAllocator.DeferTaskAsync(ExecutorId, job.TaskId, CancellationToken.None);

            Interlocked.Increment(ref cancelledCommands);
        }
Exemplo n.º 3
0
        async Task IJobExecutorContext.OnSuccessJob(TaskJob job)
        {
            DetachJob(job);

            logger.LogInformation($"Task {job.TaskId} success.");

            await taskAllocator.SuccessTaskAsync(ExecutorId, job.TaskId, job.Elapsed, CancellationToken.None);

            Interlocked.Increment(ref executedCommands);
        }
Exemplo n.º 4
0
        async Task IJobExecutorContext.OnUnhandledError(TaskJob job, Exception exception)
        {
            DetachJob(job);

            logger.LogCritical(exception, $"Task {job.TaskId} unhandled error.");

            await taskAllocator.ErrorTaskAsync(ExecutorId, job.TaskId, job.Elapsed, exception, CancellationToken.None);

            Interlocked.Increment(ref executedCommands);
            Interlocked.Increment(ref faultedCommands);
        }
Exemplo n.º 5
0
        async Task IJobExecutorContext.OnTimeoutJob(TaskJob job)
        {
            DetachJob(job);

            logger.LogWarning($"Task {job.TaskId} execution timeout.");

            await taskAllocator.ErrorTaskAsync(ExecutorId, job.TaskId, job.Elapsed, new TimeoutException("Timeout task executing."), CancellationToken.None);

            Interlocked.Increment(ref executedCommands);
            Interlocked.Increment(ref faultedCommands);
        }
Exemplo n.º 6
0
        Task IJobExecutorContext.OnStartedJob(TaskJob job)
        {
            if (!_startedJobs.TryAdd(job.TaskId, job))
            {
                throw new InvalidOperationException("Не удалось добавить задачу в список выполняемых.");
            }

            logger.LogInformation($"Task {job.TaskId} started.");

            return(Task.CompletedTask);
        }
Exemplo n.º 7
0
        private void StartJob(TaskExecutionModel executionModel, CancellationToken cancellationToken)
        {
            if (!handlerFactories.TryGetValue(executionModel.TaskModel.GetType(), out TaskHandlerMetadata handlerMetadata))
            {
                throw new InvalidOperationException();
            }

            var jobScope = serviceProvider.CreateScope();

            var job = new TaskJob(executionModel, handlerMetadata, jobScope, this);

            job.Run(cancellationToken);
        }