コード例 #1
0
ファイル: Runner.cs プロジェクト: bolvarak/aspnetcore-fux
 /// <summary>
 /// This method adds and runs a FAF task with a custom external ID
 /// </summary>
 /// <param name="taskId"></param>
 /// <param name="task"></param>
 /// <returns></returns>
 protected string FireAndForget(string taskId, DelegateFireAndForgetTask task)
 {
     // Define our ticker
     Core.Ticker ticker = new Core.Ticker();
     // Start the ticker
     ticker.Reset();
     // Add the FAF task to the instance
     _fafMap[taskId] = task
                       .Invoke(taskId, ticker)
                       .ContinueWith((asyncTask) =>
     {
         // Stop our ticker and localize the time table
         Core.TickerTimeTable tickerTimeTable = ticker.Halt();
         // Define our parts
         List <string> parts = new List <string>();
         // Define our prefix
         parts.Add($"[Internal: {asyncTask.Id} F*x: {taskId}] Task");
         // Check the cancelled flag
         if (asyncTask.IsCanceled)
         {
             parts.Add("was Cancelled in ${taskElapsed}");
         }
         // Check the completed successfully flag
         if (asyncTask.IsCompletedSuccessfully)
         {
             parts.Add("Completed Successfully in ${taskElapsed}");
         }
         // Check the faulted flag
         if (asyncTask.IsFaulted)
         {
             parts.Add("Faulted in ${taskElapsed} [Error: ${exceptionMessage}]");
         }
         // Check the completed flag
         if (asyncTask.IsCompleted)
         {
             parts.Add("Completed in ${taskElapsed}");
         }
         // Log the message
         LogMessage(
             Helper.Message.New(string.Join(' ', parts))
             .WithDataObject("taskElapsed", tickerTimeTable.Elapsed)
             .WithDataObject("exceptionMessage", asyncTask.Exception?.Message));
         // Dispose of the task
         asyncTask.Dispose();
     });
     // Return the unique ID of the FAF task
     return(taskId);
 }
コード例 #2
0
ファイル: Runner.cs プロジェクト: bolvarak/aspnetcore-fux
 /// <summary>
 /// This method logs a message when the task is done
 /// </summary>
 /// <param name="ticker"></param>
 protected void WhenTaskDone(Core.Ticker ticker) =>
 LogMessage(Helper.Message.New("Task Completed In ${tickerElapsed}")
            .WithDataObject("tickerElapsed", ticker.Halt().Elapsed));