28 lines
991 B
C#
28 lines
991 B
C#
using ParadoxSaveParser.WebAPI.Database;
|
|
using ParadoxSaveParser.WebAPI.SaveDataFilters;
|
|
|
|
namespace ParadoxSaveParser.WebAPI.BackgroundTasks;
|
|
|
|
public class BackgroundJobManager
|
|
{
|
|
private readonly ILogger _parentLogger;
|
|
private readonly Config.SaveUploadConfig _uploadConfig;
|
|
private long _lastJobId;
|
|
|
|
public BackgroundJobManager(ILogger logger, Config.SaveUploadConfig uploadConfig)
|
|
{
|
|
_parentLogger = logger;
|
|
_uploadConfig = uploadConfig;
|
|
}
|
|
|
|
public SaveParsingOperation StartNewParsingOperation(
|
|
SaveFileMetadata meta, ISaveDataFilter filter, CancellationToken ct)
|
|
{
|
|
long nextId = Interlocked.Increment(ref _lastJobId);
|
|
var contextLogger = new ContextLogger($"BackgroundJob-{nextId}", _parentLogger);
|
|
var op = new SaveParsingOperation(nextId, meta, filter,
|
|
_uploadConfig.MaxSizePlainTextBytes, contextLogger, ct);
|
|
op.StartAsync();
|
|
return op;
|
|
}
|
|
} |