Merge branch 'release/v1.0.0' of https://git.winsomnia.net/Winsomnia/MireaBackend into release/v1.0.0
Some checks failed
.NET Test Pipeline / build-and-test (push) Failing after 1m36s
Build and Deploy Docker Container / build-and-deploy (push) Successful in 2m37s

This commit is contained in:
2025-02-06 16:29:48 +03:00

View File

@ -2,6 +2,7 @@
using Cronos;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@ -191,15 +192,27 @@ public class ScheduleController(ILogger<ScheduleController> logger, IOptionsSnap
filePaths.Add((filePath, defaultCampus[i]));
}
var sync = (ScheduleSynchronizer)ActivatorUtilities.GetServiceOrCreateInstance(provider, typeof(ScheduleSynchronizer));
if (force)
{
dbContext.Lessons.RemoveRange(dbContext.Lessons.ToList());
dbContext.Lessons.RemoveRange(await dbContext.Lessons.ToListAsync());
await dbContext.SaveChangesAsync();
}
_ = sync.StartSync(filePaths, CancellationToken.None);
var scopeFactory = provider.GetRequiredService<IServiceScopeFactory>();
ThreadPool.QueueUserWorkItem(async void (_) =>
{
try
{
using var scope = scopeFactory.CreateScope();
var sync = (ScheduleSynchronizer)ActivatorUtilities.GetServiceOrCreateInstance(scope.ServiceProvider, typeof(ScheduleSynchronizer));
await sync.StartSync(filePaths, CancellationToken.None);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
});
return Ok();
}