public async Task ExecuteAsync(CancellationToken cancellationToken) { //Create de Handler process myProcessHandler = new Common.workflow.ProcessHandler(_Configuration.ProcessConfigConn); //Workflow manager Loop while (!cancellationToken.IsCancellationRequested) { //2. Execute ExecuteWatcherProcess(); System.Threading.Thread.Sleep(1000 * _Configuration.SleepDelay); } }
public async Task ExecuteAsync(CancellationToken cancellationToken) { //Create de Handler process myProcessHandler = new Common.workflow.ProcessHandler(_Configuration.ProcessConfigConn); //Infinite Loop while (true) { //2. Execute ExecuteWatcherProcess(); System.Threading.Thread.Sleep(1000 * _Configuration.SleepDelay); //await Task.Delay(1000 * _Configuration.SleepDelay); } }
private async Task RunAsync(CancellationToken cancellationToken) { CloudStorageAccount storageAccount; CloudQueueClient queueClient; CloudQueueMessage currentMessage; //TraceInfo auxiliar string txt; Setup(); //QUEUE infra storageAccount = CloudStorageAccount.Parse(myConfigData.ProcessConfigConn); queueClient = storageAccount.CreateCloudQueueClient(); //Create de Handler process myProcessHandler = new Common.workflow.ProcessHandler(myConfigData.ProcessConfigConn); //Infinite Loop while (!cancellationToken.IsCancellationRequested) { //1. Setup() Setup(); //Check if is ON/Pausa if (!myConfigData.IsPaused) { //2. how many process is running in this instance? if (myProcessHandler.CurrentProcessRunning < myConfigData.MaxCurrentProcess) { //2.1 Execute new //3. Peek Message currentMessage = GetNewMessage(queueClient); if (currentMessage != null) { //We have a new message txt = string.Format("[{0}] has a new message, messageId {1}", this.GetType().FullName, currentMessage.Id); Trace.TraceInformation(txt); //3.1 Check if is a posion Message if (!CheckPoison(currentMessage)) { //4. Good Message //4.1 Start process, fire and Forgot txt = string.Format("[{0}] Starting New Process, MessageID {1}", this.GetType().FullName, currentMessage.Id); Trace.TraceInformation(txt); myProcessHandler.Execute(currentMessage); } else { //Send dedletter message txt = string.Format("[{0}] has a new Poison message, messageId {1}", this.GetType().FullName, currentMessage.Id); Trace.TraceWarning(txt); if (SendPoisonMessage(currentMessage)) { InWorkQueue.DeleteMessage(currentMessage); txt = string.Format("[{0}] Deleted Poison message, messageId {1}", this.GetType().FullName, currentMessage.Id); Trace.TraceWarning(txt); } } } else { txt = string.Format("[{0}] has not a new message. # current process {1}", this.GetType().FullName, myProcessHandler.CurrentProcessRunning); Trace.TraceInformation(txt); } } else { txt = string.Format("[{0}] Max number of process in parallel ({1} current {2})", this.GetType().FullName, myConfigData.MaxCurrentProcess, myProcessHandler.CurrentProcessRunning); Trace.TraceInformation(txt); } } else { Trace.TraceInformation("[{0}] Workflow Manager is paused.", this.GetType().FullName); } await Task.Delay(1000* myConfigData.SleepDelay); } }