Exemplo n.º 1
0
 public void AddCycleToQueue(string queue, GraphExecutionCycle executionCycle)
 {
     if (!this.pendingCyclesQueues.ContainsKey(queue))
     {
         this.pendingCyclesQueues.Add(queue, new ConcurrentQueue <GraphExecutionCycle>());
         this.runQueueTask(queue);
     }
     this.pendingCyclesQueues[queue].Enqueue(executionCycle);
 }
Exemplo n.º 2
0
        private void runQueueTask()
        {
            this.cancelCycleToken = new CancellationTokenSource();
            queueTask             = new Task(async() =>
            {
                while (!this.cancelCycleToken.IsCancellationRequested)
                {
                    if (this.PendingCycles.Count <= 0)
                    {
                        await Task.Delay(50);
                    }
                    GraphExecutionCycle pendingCycle = null;
                    if (this.cancelCycleToken.IsCancellationRequested)
                    {
                        return;
                    }
                    while (this.PendingCycles.TryDequeue(out pendingCycle))
                    {
                        if (!this.IsRunning)
                        {
                            return;
                        }
                        currentCycle = pendingCycle;
                        if (this.cancelCycleToken.IsCancellationRequested)
                        {
                            return;
                        }
                        Task cycleTask = new Task(() =>
                        {
                            pendingCycle.Execute();
                        });
                        try
                        {
                            Task timeoutTask = Task.Delay(1000 * 60);
                            cycleTask.Start();
                            var taskResult = await Task.WhenAny(cycleTask, timeoutTask);
                            if (timeoutTask == taskResult)
                            {
                                this.AppendLog("error", string.Format("Timeout occured on last cycle from graph hash: {0}", this.UniqueHash));
                                logger.Error("Timeout exceeded for the cycle, skipping ..");
                                cycleTask.Dispose();
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex, "Error when executing the cycle");
                        }

                        currentCycle = null;
                    }
                }
                return;
            });
            queueTask.Start();
        }
Exemplo n.º 3
0
        private void runQueueTask(string queueName)
        {
            this.cancelCycleToken = new CancellationTokenSource();
            var task = new Task(async() =>
            {
                int failedCycleCount = 0;
                while (!this.cancelCycleToken.IsCancellationRequested)
                {
                    if (this.pendingCyclesQueues[queueName].Count <= 0)
                    {
                        await Task.Delay(150);
                    }
                    GraphExecutionCycle pendingCycle = null;
                    if (this.cancelCycleToken.IsCancellationRequested)
                    {
                        return;
                    }
                    while (this.pendingCyclesQueues[queueName].TryDequeue(out pendingCycle))
                    {
                        try
                        {
                            if (!this.IsRunning)
                            {
                                return;
                            }
                            currentCycle = pendingCycle;
                            if (this.cancelCycleToken.IsCancellationRequested)
                            {
                                return;
                            }
                            Task cycleTask = new Task(() =>
                            {
                                pendingCycle.Execute();
                            });
                            try
                            {
                                Task timeoutTask = Task.Delay(pendingCycle.GetCycleMaxExecutionTime());
                                cycleTask.Start();
                                var taskResult = await Task.WhenAny(cycleTask, timeoutTask);
                                if (timeoutTask == taskResult)
                                {
                                    this.AppendLog("error", string.Format("Timeout occured on last cycle from graph hash: {0}", this.UniqueHash));
                                    logger.Error("Timeout exceeded for the cycle, skipping ..");
                                    cycleTask.Dispose();
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex, "Error when executing the cycle");
                                failedCycleCount++;
                            }
                        }
                        catch (Exception ex2)
                        {
                            logger.Error(ex2, "Error when executing the cycle");
                            failedCycleCount++;
                        }
                        finally
                        {
                            currentCycle = null;
                            //if(failedCycleCount >= MAX_FAILED_CYCLE)
                            //{
                            //    failedCycleCount = 0;
                            //    this.Stop(false);
                            //}
                        }
                    }
                }
                return;
            });

            queueTaskCycleThreads.Add(queueName, task);
            task.Start();
        }