ScheduleEngine.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. using InABox.Rpc;
  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. //var transport = new RpcClientPipeTransport(DatabaseServerProperties.GetPipeName(Properties.Server));
  35. //ClientFactory.SetClientType(typeof(RpcClient<>), Platform.SchedulerEngine, Version, transport);
  36. CheckConnection();
  37. Logger.Send(LogType.Information, "", "Starting Scheduler: ");
  38. scheduler.Start();
  39. }
  40. catch (Exception ex)
  41. {
  42. Logger.Send(LogType.Error, "", "Error: " + ex.Message + "\n" + ex.StackTrace);
  43. throw;
  44. }
  45. }
  46. public override void Stop()
  47. {
  48. scheduler.Stop();
  49. }
  50. }
  51. }