/// <inheritdoc/> public void Register(IExecutionTask task) { if (task is null) { throw new ArgumentNullException(nameof(task)); } var start = false; // first we initialize the task execution state. // This can be done without acquiring a lock since we only // interact with the task object itself. _stateMachine.TryInitializeTask(task); task.IsRegistered = true; lock (_sync) { if (_stateMachine.RegisterTask(task)) { WorkQueue work = task.IsSerial ? _serial : _work; work.Push(task); start = ShouldStartProcessing(); } else { _suspended.Enqueue(task); } } if (start) { TryContinue(); } }
public void TaskError(IExecutionTask task, IError error) { for (var i = 0; i < _listeners.Length; i++) { _listeners[i].TaskError(task, error); } }
public override void TaskError( IExecutionTask task, IError error ) { _logger.LogError(error.Exception, $"During execution of the task {task} the error {ConvertErrorToString(error)} occurred."); }
/// <inheritdoc/> public void Register(IReadOnlyList <IExecutionTask> tasks) { if (tasks is null) { throw new ArgumentNullException(nameof(tasks)); } if (tasks.Count == 1) { Register(tasks[0]); return; } var started = false; // first we initialize the task execution state. // This can be done without acquiring a lock since we only // interact with the task object itself. for (var i = 0; i < tasks.Count; i++) { IExecutionTask task = tasks[i]; _stateMachine.TryInitializeTask(task); task.IsRegistered = true; } lock (_sync) { var start = false; for (var i = 0; i < tasks.Count; i++) { IExecutionTask task = tasks[i]; if (_stateMachine.RegisterTask(task)) { WorkQueue work = task.IsSerial ? _serial : _work; work.Push(task); start = true; } else { _suspended.Enqueue(task); } } if (start) { started = TryStartProcessingUnsafe(); } } if (started) { // we invoke the scale diagnostic event after leaving the lock to not block // if a an event listener is badly implemented. _diagnosticEvents.StartProcessing(_requestContext); } }
public override void TaskError(IExecutionTask task, IError error) { if (error.Exception != null) { LogError(new EventId(5, "GraphQL Task Error"), error.Exception); } base.TaskError(task, error); }
public void Enqueue(IExecutionTask executionTask) { if (executionTask is null) { throw new ArgumentNullException(nameof(executionTask)); } AppendTask(ref _head, executionTask); IsEmpty = false; }
/// <inheritdoc/> public void Register(IReadOnlyList <IExecutionTask> tasks) { if (tasks is null) { throw new ArgumentNullException(nameof(tasks)); } if (tasks.Count == 1) { Register(tasks[0]); return; } var start = false; // first we initialize the task execution state. // This can be done without acquiring a lock since we only // interact with the task object itself. for (var i = 0; i < tasks.Count; i++) { IExecutionTask task = tasks[i]; _stateMachine.TryInitializeTask(task); task.IsRegistered = true; } lock (_sync) { for (var i = 0; i < tasks.Count; i++) { IExecutionTask task = tasks[i]; if (_stateMachine.RegisterTask(task)) { WorkQueue work = task.IsSerial ? _serial : _work; work.Push(task); start = true; } else { _suspended.Enqueue(task); } } if (start) { start = ShouldStartProcessing(); } } if (start) { TryContinue(); } }
private void ReportError(IExecutionTask task, IError error) { if (task is null) { throw new ArgumentNullException(nameof(task)); } if (error is null) { throw new ArgumentNullException(nameof(error)); } AssertInitialized(); if (error is AggregateError aggregateError) { foreach (IError?innerError in aggregateError.Errors) { ReportSingle(innerError); } } else { ReportSingle(error); } void ReportSingle(IError singleError) { AddProcessedError(ErrorHandler.Handle(singleError)); } void AddProcessedError(IError processed) { if (processed is AggregateError ar) { foreach (IError?ie in ar.Errors) { Result.AddError(ie); DiagnosticEvents.TaskError(task, ie); } } else { Result.AddError(processed); DiagnosticEvents.TaskError(task, processed); } } }
public IDisposable RunTask(IExecutionTask task) { if (_listeners.Length == 0) { return(ExecutionDiagnosticEventListener.EmptyScope); } var scopes = new IDisposable[_resolverListener.Length]; for (var i = 0; i < _resolverListener.Length; i++) { scopes[i] = _resolverListener[i].RunTask(task); } return(new AggregateActivityScope(scopes)); }
public override void CompleteTask(IQueryPlanState state, IExecutionTask task) { Debug.Assert(ReferenceEquals(task.State, this), "The task must be part of this step."); if (task is ResolverTask { ChildTasks : { Count : > 0 } } resolverTask) { foreach (ResolverTask?childTask in resolverTask.ChildTasks) { state.Selections.Add(childTask.Selection.Id); } state.RegisterUnsafe(resolverTask.ChildTasks); } }
public IActivityScope RunTask(IExecutionTask task) { if (_listeners.Length == 0) { return(_empty); } var scopes = new IActivityScope[_resolverListener.Length]; for (var i = 0; i < _resolverListener.Length; i++) { scopes[i] = _resolverListener[i].RunTask(task); } return(new AggregateActivityScope(scopes)); }
private void ReportError(IExecutionTask task, IError error) { if (task is null) { throw new ArgumentNullException(nameof(task)); } if (error is null) { throw new ArgumentNullException(nameof(error)); } AssertInitialized(); error = ErrorHandler.Handle(error); Result.AddError(error); DiagnosticEvents.TaskError(task, error); }
void IQueryPlanState.RegisterUnsafe(IReadOnlyList <IExecutionTask> tasks) { for (var i = 0; i < tasks.Count; i++) { IExecutionTask task = tasks[i]; _stateMachine.TryInitializeTask(task); task.IsRegistered = true; if (_stateMachine.RegisterTask(task)) { WorkQueue work = task.IsSerial ? _serial : _work; work.Push(task); } else { _suspended.Enqueue(task); } } }
public void CopyTo(WorkQueue work, WorkQueue serial, QueryPlanStateMachine stateMachine) { IExecutionTask?head = _head; _head = null; while (head is not null) { IExecutionTask current = head; head = head.Next; current.Next = null; if (stateMachine.IsSuspended(current)) { AppendTask(ref _head, current); } else { (current.IsSerial ? serial : work).Push(current); } } IsEmpty = _head is null; }
public void TaskError(IExecutionTask task, IError error) { }
public IDisposable RunTask(IExecutionTask task) => this;
public void Register(IExecutionTask task) { _stats.TaskCreated(); _channel.Writer.TryWrite(task); }
void IExecutionTaskContext.Register(IExecutionTask task) { Scheduler.Register(task); }
void IExecutionTaskContext.ReportError(IExecutionTask task, IError error) { ReportError(task, error); }
/// <summary> /// Defines if this execution step owns the given task. /// </summary> /// <param name="task"> /// The execution task that is evaluated. /// </param> /// <returns> /// <c>true</c> if the task is owned by this step; otherwise, <c>false</c>. /// </returns> public virtual bool IsOwningTask(IExecutionTask task) => false;
/// <summary> /// Completes a task that was spawned from this execution step. /// </summary> /// <param name="state"> /// The current query plan execution state. /// </param> /// <param name="task"> /// The execution task that was spawned from the execution task. /// </param> public virtual void CompleteTask(IQueryPlanState state, IExecutionTask task) { }
private void ReportError(IExecutionTask task, IError error) { error = ErrorHandler.Handle(error); Result.AddError(error); DiagnosticEvents.TaskError(task, error); }
void IExecutionTaskContext.Completed(IExecutionTask task) { AssertInitialized(); Scheduler.Complete(task); }
IDisposable IExecutionTaskContext.Track(IExecutionTask task) => DiagnosticEvents.RunTask(task);
private static void AppendTask(ref IExecutionTask?head, IExecutionTask executionTask) { executionTask.Previous = null; executionTask.Next = head; head = executionTask; }
void IExecutionTaskContext.ReportError(IExecutionTask task, Exception exception) { ReportError(task, ErrorHandler.CreateUnexpectedError(exception).Build()); }
/// <summary> /// Allows tasks to be added which will be executed when the Block /// is executed. /// </summary> /// <param name="task">Task to be executed</param> public void RegisterProvider(IExecutionTask task) { tasks.Add(task); }
IDisposable IExecutionTaskContext.Track(IExecutionTask task) { AssertInitialized(); return(DiagnosticEvents.RunTask(task)); }
public async Task ExecuteAsync() { _stateMachine.Start(); if (_suspended.HasWork) { _suspended.CopyTo(_work, _serial, _stateMachine); } _processing = true; IExecutionTask?[] buffer = _buffer; RESTART: try { do { var work = TryTake(buffer); if (work != 0) { if (!buffer[0] !.IsSerial) { for (var i = 0; i < work; i++) { buffer[i] !.BeginExecute(_requestAborted); buffer[i] = null; } } else { try { _batchDispatcher.DispatchOnSchedule = true; for (var i = 0; i < work; i++) { IExecutionTask task = buffer[i] !; task.BeginExecute(_requestAborted); await task.WaitForCompletionAsync(_requestAborted) .ConfigureAwait(false); buffer[i] = null; if (_requestAborted.IsCancellationRequested) { break; } } } finally { _batchDispatcher.DispatchOnSchedule = false; } } } else { if (_work.HasRunningTasks || _serial.HasRunningTasks) { await Task.Yield(); } break; } } while (!_requestAborted.IsCancellationRequested); }
/// <inheritdoc /> public virtual IActivityScope RunTask(IExecutionTask task) => EmptyScope;