private void DetachJob(TaskJob job) { if (!_startedJobs.TryRemove(job.TaskId, out TaskJob removed)) { throw new InvalidOperationException(); } removed.Dispose(); }
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); }
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); }
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); }
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); }
Task IJobExecutorContext.OnStartedJob(TaskJob job) { if (!_startedJobs.TryAdd(job.TaskId, job)) { throw new InvalidOperationException("Не удалось добавить задачу в список выполняемых."); } logger.LogInformation($"Task {job.TaskId} started."); return(Task.CompletedTask); }
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); }