Skip to content

Commit

Permalink
fix for fresh startup (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlapaglia authored Jan 29, 2024
1 parent c169956 commit 114e557
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions OpenAlprWebhookProcessor/Hydration/HydrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public async Task ScheduleHydrationAsync(CancellationToken cancellationToken)

var agent = await processorContext.Agents.FirstOrDefaultAsync(cancellationToken);

if (string.IsNullOrWhiteSpace(agent.Uid))
{
var logger = scope.ServiceProvider.GetRequiredService<ILogger<HydrationService>>();
logger.LogWarning("Agent UID is not set. Cannot schedule hydration.");
return;
}

if (agent.ScheduledScrapingIntervalMinutes == null)
{
RecurringJob.RemoveIfExists(agent.Uid);
Expand Down
11 changes: 10 additions & 1 deletion OpenAlprWebhookProcessor/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public void ConfigureServices(IServiceCollection services)
using (var context = new ProcessorContext(processorOptionsBuilder.Options))
{
context.Database.Migrate();
var agent = context.Agents.FirstOrDefault();

if (agent == null)
{
agent = new Data.Agent();

context.Agents.Add(agent);
context.SaveChanges();
}
}

var optionsBuilder = new DbContextOptionsBuilder<UsersContext>();
Expand Down Expand Up @@ -202,7 +211,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddSingleton<WebPushNotificationProducer>();
services.AddSingleton<IHostedService>(p => p.GetService<WebPushNotificationProducer>());

services.AddSingleton<WebsocketClientOrganizer>();
services.AddSingleton<IHostedService>(p => p.GetService<WebsocketClientOrganizer>());

Expand Down

0 comments on commit 114e557

Please sign in to comment.