AipDatabaseSchedulerInvocable.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Coravel.Invocable;
  2. using System.Diagnostics;
  3. namespace AipDatabase.API.Scheduler
  4. {
  5. public class AipDatabaseSchedulerInvocable : IInvocable
  6. {
  7. private readonly ILogger<AipDatabaseSchedulerInvocable> _log;
  8. public AipDatabaseSchedulerInvocable(ILogger<AipDatabaseSchedulerInvocable> log)
  9. {
  10. _log = log;
  11. }
  12. public async Task Invoke()
  13. {
  14. Stopwatch sw = Stopwatch.StartNew();
  15. sw.Start();
  16. _log.LogInformation("*** AipDatabaseScheduler Schedule Job Start.");
  17. try
  18. {
  19. var task = Task.Run(() =>
  20. {
  21. Thread.Sleep(1000);
  22. });
  23. await task;
  24. }
  25. catch (Exception e)
  26. {
  27. _log.LogError($"*** AipDatabaseScheduler Schedule Job .Error. Exception: {e}");
  28. }
  29. sw.Stop();
  30. _log.LogInformation("*** AipDatabaseScheduler Schedule Job ..End. {0} ms.", sw.ElapsedMilliseconds);
  31. }
  32. }
  33. }