2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 16:33:43 -04:00

JournalService setup work in progress

This commit is contained in:
2024-05-07 12:02:43 +01:00
parent d59914e277
commit f3ce62b551
12 changed files with 215 additions and 85 deletions

View File

@ -7,6 +7,6 @@ public class ModulesInfoController(IModulesInfoService modulesInfo) : Controller
[HttpGet]
public async Task<IActionResult> Get()
{
return Ok(modulesInfo.Get());
return Ok(await modulesInfo.Get());
}
}

View File

@ -7,12 +7,36 @@ public interface IModulesInfoService : IJournalHandler<ModuleInfoFile>;
public class ModulesInfoService(
ILogger<ModulesInfoService> logger,
IOptions<PulsarConfiguration> options,
IEventHubContext hub)
: JournalHandlerBase<ModuleInfoFile>(logger), IModulesInfoService
IEventHubContext hub) : IModulesInfoService
{
public override string FileName => FileHandlerService.ModulesInfoFileName;
public string FileName => FileHandlerService.ModulesInfoFileName;
public override async Task HandleFile(string filePath)
public bool ValidateFile(string filePath)
{
if (!File.Exists(filePath))
{
logger.LogWarning("Journal file {JournalFile} does not exist", filePath);
return false;
}
var fileInfo = new FileInfo(filePath);
if (!string.Equals(fileInfo.Name, FileName, StringComparison.InvariantCultureIgnoreCase))
{
logger.LogWarning("Journal file {name} is not valid");
return false;
}
if (fileInfo.Length == 0)
{
logger.LogWarning("Journal file {name} is empty", filePath);
return false;
}
return true;
}
public async Task HandleFile(string filePath)
{
if (!ValidateFile(filePath))
{
@ -31,7 +55,7 @@ public class ModulesInfoService(
await hub.Clients.All.ModuleInfoUpdated(moduleInfo);
}
public override async Task<ModuleInfoFile> Get()
public async Task<ModuleInfoFile> Get()
{
var moduleInfoFile = Path.Combine(options.Value.JournalDirectory, FileName);
@ -47,4 +71,4 @@ public class ModulesInfoService(
logger.LogWarning("Failed to deserialize module info file {ModuleInfoFile}", moduleInfoFile);
return new ModuleInfoFile();
}
}
}