ScheduleEngine.cs 1.6 KB

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