123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Threading.Tasks;
- using Comal.TaskScheduler.Shared;
- using InABox.IPC;
- using InABox.Clients;
- using InABox.Core;
- namespace PRSServer
- {
- internal class ScheduleEngine : Engine<ScheduleServerProperties>
- {
- private readonly Scheduler scheduler = new();
- private void CheckConnection()
- {
- // Wait for server connection
- while (!Client.Ping())
- {
- Logger.Send(LogType.Error, "", "Database server unavailable. Trying again in 30 seconds...");
- Task.Delay(30_000).Wait();
- Logger.Send(LogType.Information, "", "Retrying connection...");
- }
- ClientFactory.SetBypass();
- }
- public override void Run()
- {
- try
- {
- if (string.IsNullOrWhiteSpace(Properties.Server))
- {
- Logger.Send(LogType.Error, "", "Server is blank!");
- return;
- }
- ClientFactory.SetClientType(typeof(IPCClient<>), Platform.SchedulerEngine, Version, DatabaseServerProperties.GetPipeName(Properties.Server));
- CheckConnection();
- Logger.Send(LogType.Information, "", "Starting Scheduler: ");
- scheduler.Start();
- }
- catch (Exception ex)
- {
- Logger.Send(LogType.Error, "", "Error: " + ex.Message + "\n" + ex.StackTrace);
- throw;
- }
- }
- public override void Stop()
- {
- scheduler.Stop();
- }
- }
- }
|