ScheduleEngine.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Threading.Tasks;
  3. using Comal.TaskScheduler.Shared;
  4. using InABox.IPC;
  5. using InABox.Clients;
  6. using InABox.Core;
  7. namespace PRSServer
  8. {
  9. internal class ScheduleEngine : Engine<ScheduleServerProperties>
  10. {
  11. private readonly Scheduler scheduler = new();
  12. private void CheckConnection()
  13. {
  14. // Wait for server connection
  15. while (!Client.Ping())
  16. {
  17. Logger.Send(LogType.Error, "", "Database server unavailable. Trying again in 30 seconds...");
  18. Task.Delay(30_000).Wait();
  19. Logger.Send(LogType.Information, "", "Retrying connection...");
  20. }
  21. ClientFactory.SetBypass();
  22. }
  23. public override void Run()
  24. {
  25. try
  26. {
  27. if (string.IsNullOrWhiteSpace(Properties.Server))
  28. {
  29. Logger.Send(LogType.Error, "", "Server is blank!");
  30. return;
  31. }
  32. ClientFactory.SetClientType(typeof(IPCClient<>), Platform.SchedulerEngine, Version, DatabaseServerProperties.GetPipeName(Properties.Server));
  33. CheckConnection();
  34. Logger.Send(LogType.Information, "", "Starting Scheduler: ");
  35. scheduler.Start();
  36. }
  37. catch (Exception ex)
  38. {
  39. Logger.Send(LogType.Error, "", "Error: " + ex.Message + "\n" + ex.StackTrace);
  40. throw;
  41. }
  42. }
  43. public override void Stop()
  44. {
  45. scheduler.Stop();
  46. }
  47. }
  48. }