Files
SPT-Server-Build/Libraries/SPTarkov.Server.Core/Callbacks/SaveCallbacks.cs
T
Jesse 2c52012740 Further async changes (#387)
* Further async changes
- SaveServer & Backup Server are now async
- Anything that ties in with SaveServer saving (Such as callbacks) are now async
- Various async util methods added
- Removed two wrapper methods and switched code over to use the actual method

* Update test
2025-06-09 20:09:12 +01:00

39 lines
1007 B
C#

using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.DI;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
namespace SPTarkov.Server.Core.Callbacks;
[Injectable(TypePriority = OnLoadOrder.SaveCallbacks)]
public class SaveCallbacks(
SaveServer _saveServer,
ConfigServer _configServer,
BackupService _backupService
)
: IOnLoad, IOnUpdate
{
private readonly CoreConfig _coreConfig = _configServer.GetConfig<CoreConfig>();
public async Task OnLoad()
{
_backupService.StartBackupSystem();
await _saveServer.LoadAsync();
}
public async Task<bool> OnUpdate(long secondsSinceLastRun)
{
if (secondsSinceLastRun < _coreConfig.ProfileSaveIntervalInSeconds)
{
// Not enough time has passed since last run, exit early
return false;
}
await _saveServer.SaveAsync();
return true;
}
}