Improved how OnUpdate is handled
This commit is contained in:
@@ -13,16 +13,14 @@ namespace SPTarkov.Server.Core.Callbacks;
|
||||
[Injectable(TypePriority = OnUpdateOrder.HideoutCallbacks)]
|
||||
public class HideoutCallbacks(
|
||||
HideoutController _hideoutController,
|
||||
ConfigServer _configServer,
|
||||
TimeUtil _timeUtil
|
||||
ConfigServer _configServer
|
||||
) : IOnUpdate
|
||||
{
|
||||
private readonly HideoutConfig _hideoutConfig = _configServer.GetConfig<HideoutConfig>();
|
||||
private long _lastRunOnUpdateTimestamp = long.MaxValue;
|
||||
|
||||
public Task<bool> OnUpdate(long secondsSinceLastRun)
|
||||
{
|
||||
if (_timeUtil.GetTimeStamp() <= _lastRunOnUpdateTimestamp + _hideoutConfig.RunIntervalSeconds)
|
||||
if (secondsSinceLastRun < _hideoutConfig.RunIntervalSeconds)
|
||||
{
|
||||
// Not enough time has passed since last run, exit early
|
||||
return Task.FromResult(false);
|
||||
@@ -30,9 +28,6 @@ public class HideoutCallbacks(
|
||||
|
||||
_hideoutController.Update();
|
||||
|
||||
// Store last completion time for later use
|
||||
_lastRunOnUpdateTimestamp = _timeUtil.GetTimeStamp();
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,26 +16,21 @@ public class InsuranceCallbacks(
|
||||
InsuranceController _insuranceController,
|
||||
InsuranceService _insuranceService,
|
||||
HttpResponseUtil _httpResponseUtil,
|
||||
ConfigServer _configServer,
|
||||
TimeUtil _timeUtil
|
||||
ConfigServer _configServer
|
||||
)
|
||||
: IOnUpdate
|
||||
{
|
||||
private readonly InsuranceConfig _insuranceConfig = _configServer.GetConfig<InsuranceConfig>();
|
||||
private long _lastRunOnUpdateTimestamp = long.MaxValue;
|
||||
|
||||
public Task<bool> OnUpdate(long secondsSinceLastRun)
|
||||
{
|
||||
if (_timeUtil.GetTimeStamp() <= _lastRunOnUpdateTimestamp + _insuranceConfig.RunIntervalSeconds)
|
||||
if (secondsSinceLastRun < _insuranceConfig.RunIntervalSeconds)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
_insuranceController.ProcessReturn();
|
||||
|
||||
// Store last completion time for later use
|
||||
_lastRunOnUpdateTimestamp = _timeUtil.GetTimeStamp();
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,23 +18,22 @@ public class RagfairCallbacks(
|
||||
RagfairController _ragfairController,
|
||||
RagfairTaxService _ragfairTaxService,
|
||||
RagfairPriceService _ragfairPriceService,
|
||||
ConfigServer _configServer,
|
||||
TimeUtil _timeUtil
|
||||
ConfigServer _configServer
|
||||
) : IOnLoad, IOnUpdate
|
||||
{
|
||||
private readonly RagfairConfig _ragfairConfig = _configServer.GetConfig<RagfairConfig>();
|
||||
private long _lastRunOnUpdateTimestamp = long.MaxValue;
|
||||
|
||||
public Task OnLoad()
|
||||
{
|
||||
_ragfairServer.Load();
|
||||
_ragfairPriceService.Load();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<bool> OnUpdate(long secondsSinceLastRun)
|
||||
{
|
||||
if (_timeUtil.GetTimeStamp() <= _lastRunOnUpdateTimestamp + _ragfairConfig.RunIntervalSeconds)
|
||||
if (secondsSinceLastRun < _ragfairConfig.RunIntervalSeconds)
|
||||
{
|
||||
// Not enough time has passed since last run, exit early
|
||||
return Task.FromResult(false);
|
||||
@@ -49,9 +48,6 @@ public class RagfairCallbacks(
|
||||
// Process all offers / expire offers
|
||||
_ragfairServer.Update();
|
||||
|
||||
// Store last completion time for later use
|
||||
_lastRunOnUpdateTimestamp = _timeUtil.GetTimeStamp();
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,11 @@ namespace SPTarkov.Server.Core.Callbacks;
|
||||
public class SaveCallbacks(
|
||||
SaveServer _saveServer,
|
||||
ConfigServer _configServer,
|
||||
BackupService _backupService,
|
||||
TimeUtil _timeUtil
|
||||
BackupService _backupService
|
||||
)
|
||||
: IOnLoad, IOnUpdate
|
||||
{
|
||||
private readonly CoreConfig _coreConfig = _configServer.GetConfig<CoreConfig>();
|
||||
private long _lastRunOnUpdateTimestamp = long.MaxValue;
|
||||
|
||||
public async Task OnLoad()
|
||||
{
|
||||
@@ -27,7 +25,7 @@ public class SaveCallbacks(
|
||||
|
||||
public Task<bool> OnUpdate(long secondsSinceLastRun)
|
||||
{
|
||||
if (_timeUtil.GetTimeStamp() <= _lastRunOnUpdateTimestamp + _coreConfig.ProfileSaveIntervalInSeconds)
|
||||
if (secondsSinceLastRun < _coreConfig.ProfileSaveIntervalInSeconds)
|
||||
{
|
||||
// Not enough time has passed since last run, exit early
|
||||
return Task.FromResult(false);
|
||||
@@ -35,9 +33,6 @@ public class SaveCallbacks(
|
||||
|
||||
_saveServer.Save();
|
||||
|
||||
// Store last completion time for later use
|
||||
_lastRunOnUpdateTimestamp = _timeUtil.GetTimeStamp();
|
||||
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,15 +123,15 @@ public class App(
|
||||
|
||||
try
|
||||
{
|
||||
await updateable.OnUpdate(secondsSinceLastRun);
|
||||
if(await updateable.OnUpdate(secondsSinceLastRun))
|
||||
{
|
||||
_onUpdateLastRun[updateableName] = _timeUtil.GetTimeStamp();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
LogUpdateException(err, updateable);
|
||||
}
|
||||
|
||||
// Set last run after try catch, so if an exception is caused the task is seen as failed.
|
||||
_onUpdateLastRun[updateableName] = _timeUtil.GetTimeStamp();
|
||||
}
|
||||
|
||||
await Task.Delay(5000, _appLifeTime.ApplicationStopping);
|
||||
|
||||
Reference in New Issue
Block a user