2020-04-12 04:18:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wabbajack.BuildServer.Model.Models;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.BackendServices
|
|
|
|
|
{
|
|
|
|
|
public abstract class ABackendService
|
|
|
|
|
{
|
|
|
|
|
protected ABackendService(SqlService sql, AppSettings settings, TimeSpan pollRate)
|
|
|
|
|
{
|
|
|
|
|
Sql = sql;
|
|
|
|
|
Settings = settings;
|
|
|
|
|
PollRate = pollRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TimeSpan PollRate { get; }
|
|
|
|
|
|
|
|
|
|
public async Task RunLoop(CancellationToken token)
|
|
|
|
|
{
|
2020-04-28 21:43:42 +00:00
|
|
|
|
Utils.Log($"Starting loop for {GetType()}");
|
2020-04-12 04:18:21 +00:00
|
|
|
|
while (!token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await Execute();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2020-04-28 21:43:42 +00:00
|
|
|
|
Utils.Log($"Error executing {GetType()}");
|
2020-04-12 04:18:21 +00:00
|
|
|
|
Utils.Log(ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Task.Delay(PollRate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract Task Execute();
|
|
|
|
|
|
|
|
|
|
protected AppSettings Settings { get; set; }
|
|
|
|
|
|
|
|
|
|
protected SqlService Sql { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|