/// <summary> /// <see cref="IBackgroundTaskQueue.QueueAgentRun(AgentRunnerProcess)"></see> /// </summary> public void QueueAgentRun(AgentRunnerProcess workItem) { if (workItem == null) { throw new ArgumentNullException(nameof(workItem)); } this.workItems.Enqueue(workItem); this.signal.Release(); }
/// <summary> /// <see cref="IBackgroundTaskQueue.StopAsync(string)"></see> /// </summary> public Task StopAsync(string channel) { this.channelDeleted = channel; if (this.currentRunProcess != null && this.currentRunProcess.Channel.Equals(channel)) { if (this.currentRunProcess.ProcessWrapper != null) { this.currentRunProcess.ProcessWrapper.StopProcess(); this.currentRunProcess = null; } } this.workItems.Clear(); return(Task.CompletedTask); }
/// <summary> /// <see cref="IBackgroundTaskQueue.DequeueAgentRunAsync(CancellationToken)"></see> /// </summary> public async Task <AgentRunnerProcess> DequeueAgentRunAsync(CancellationToken cancellationToken) { await this.signal.WaitAsync(cancellationToken); AgentRunnerProcess workItem; do { if (!this.workItems.TryDequeue(out workItem)) { return(null); } } while (workItem.Channel.Equals(this.channelDeleted)); this.currentRunProcess = workItem; return(workItem); }