Release v1.0.0 #16
.editorconfig.envDbInitializer.csDependencyInjection.csnuget.config
.gitea/workflows
.gitignoreApiDto
ApiDto.csproj
Backend.slnDockerfileCommon
AuthRoles.csCacheType.csDatabaseType.csOAuthAction.csOAuthProvider.csPairPeriodTime.csPasswordPolicy.csTwoFactorAuthentication.cs
Requests
Responses
AvailableOAuthProvidersResponse.csCampusBasicInfoResponse.csCampusDetailsResponse.cs
Configuration
DisciplineResponse.csFacultyResponse.csGroupDetailsResponse.csGroupResponse.csLectureHallDetailsResponse.csLectureHallResponse.csLessonTypeResponse.csProfessorResponse.csScheduleResponse.csTotpKeyResponse.csUserResponse.csEndpoint
Backend.httpISaveSettings.cs
README.mdCommon
Attributes
BadRequestResponseAttribute.csCacheMaxAgeAttribute.csLocalhostAttribute.csMaintenanceModeIgnoreAttribute.csNotFoundResponseAttribute.csSwaggerDefaultAttribute.csTokenAuthenticationAttribute.cs
Exceptions
Interfaces
MapperDto
AvailableProvidersConverter.csPairPeriodTimeConverter.csPasswordPolicyConverter.csTwoFactorAuthenticationConverter.csUserConverter.cs
Services
Configuration
Core
BackgroundTasks
Middleware
CacheMaxAgeMiddleware.csCookieAuthorizationMiddleware.csCustomExceptionHandlerMiddleware.csJwtRevocationMiddleware.csMaintenanceModeMiddleware.cs
Startup
Model
SwaggerOptions
ActionResultSchemaFilter.csConfigureSwaggerOptions.csSwaggerDefaultValues.csSwaggerExampleFilter.csSwaggerTagSchemeFilter.cs
Validation
Controllers
BaseController.csConfigurationBaseController.cs
Endpoint.csprojProgram.csSetupConfiguration
V1
AuthController.csCampusController.csDisciplineController.csFacultyController.csGroupController.csImportController.csLectureHallController.csLessonTypeController.csProfessorController.csScheduleController.csSecurityController.cs
WeatherForecastController.csSync
WeatherForecast.cswwwroot
css
swagger
Security
Common
CookieNames.cs
DependencyInjection.csDomain
Interfaces
Model
OAuth2
ViewModel
Properties
Security.csprojServices
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus
Queries
Discipline
Queries
Faculty
Queries
Group
Queries
LectureHall
Queries
Professor
Queries
GetProfessorDetails
GetProfessorDetailsBySearch
GetProfessorList
Schedule
Queries
TypeOfOccupation
Interfaces
Domain
Domain.csproj
Schedule
Migrations
MysqlMigrations
Migrations
20240601023106_InitialMigration.Designer.cs20240601023106_InitialMigration.cs20241027034820_RemoveUnusedRef.Designer.cs20241027034820_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
MysqlMigrations.csprojPsqlMigrations
Migrations
20240601021702_InitialMigration.Designer.cs20240601021702_InitialMigration.cs20241027032753_RemoveUnusedRef.Designer.cs20241027032753_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
PsqlMigrations.csprojSqliteMigrations
Persistence
Common
BaseDbContext.csConfigurationResolver.csDatabaseProvider.csDbContextFactory.csModelBuilderExtensions.cs
Contexts
Schedule
EntityTypeConfigurations
Persistence.csprojUberDbContext.cs@ -4,12 +4,7 @@ namespace Mirea.Api.Endpoint.Common.Services;
|
|||||||
|
|
||||||
public static class ScheduleSyncManager
|
public static class ScheduleSyncManager
|
||||||
{
|
{
|
||||||
public static event Action? OnUpdateIntervalRequested;
|
|
||||||
public static event Action? OnForceSyncRequested;
|
public static event Action? OnForceSyncRequested;
|
||||||
|
|
||||||
public static void RequestIntervalUpdate() =>
|
|
||||||
OnUpdateIntervalRequested?.Invoke();
|
|
||||||
|
|
||||||
public static void RequestForceSync() =>
|
public static void RequestForceSync() =>
|
||||||
OnForceSyncRequested?.Invoke();
|
OnForceSyncRequested?.Invoke();
|
||||||
}
|
}
|
@ -15,23 +15,32 @@ namespace Mirea.Api.Endpoint.Configuration.Core.BackgroundTasks;
|
|||||||
public class ScheduleSyncService : IHostedService, IDisposable
|
public class ScheduleSyncService : IHostedService, IDisposable
|
||||||
{
|
{
|
||||||
private Timer? _timer;
|
private Timer? _timer;
|
||||||
private readonly IOptionsMonitor<GeneralConfig> _generalConfigMonitor;
|
private string _cronUpdate;
|
||||||
private readonly ILogger<ScheduleSyncService> _logger;
|
private readonly ILogger<ScheduleSyncService> _logger;
|
||||||
private CancellationTokenSource _cancellationTokenSource = new();
|
private CancellationTokenSource _cancellationTokenSource = new();
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private readonly IDisposable? _onChangeUpdateCron;
|
||||||
|
|
||||||
public ScheduleSyncService(IOptionsMonitor<GeneralConfig> generalConfigMonitor, ILogger<ScheduleSyncService> logger, IServiceProvider serviceProvider)
|
public ScheduleSyncService(IOptionsMonitor<GeneralConfig> generalConfigMonitor, ILogger<ScheduleSyncService> logger, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_generalConfigMonitor = generalConfigMonitor;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
|
_cronUpdate = generalConfigMonitor.CurrentValue.ScheduleSettings!.CronUpdateSchedule;
|
||||||
|
|
||||||
ScheduleSyncManager.OnForceSyncRequested += OnForceSyncRequested;
|
ScheduleSyncManager.OnForceSyncRequested += OnForceSyncRequested;
|
||||||
ScheduleSyncManager.OnUpdateIntervalRequested += OnUpdateIntervalRequested;
|
_onChangeUpdateCron = generalConfigMonitor.OnChange((config) =>
|
||||||
|
{
|
||||||
|
if (config.ScheduleSettings?.CronUpdateSchedule == null || _cronUpdate == config.ScheduleSettings.CronUpdateSchedule)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_cronUpdate = config.ScheduleSettings.CronUpdateSchedule;
|
||||||
|
OnUpdateIntervalRequested();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnForceSyncRequested()
|
private void OnForceSyncRequested()
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("It was requested to synchronize the data immediately.");
|
||||||
StopAsync(CancellationToken.None).ContinueWith(_ =>
|
StopAsync(CancellationToken.None).ContinueWith(_ =>
|
||||||
{
|
{
|
||||||
_cancellationTokenSource = new CancellationTokenSource();
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
@ -41,6 +50,7 @@ public class ScheduleSyncService : IHostedService, IDisposable
|
|||||||
|
|
||||||
private void OnUpdateIntervalRequested()
|
private void OnUpdateIntervalRequested()
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("It was requested to update the time interval immediately.");
|
||||||
StopAsync(CancellationToken.None).ContinueWith(_ =>
|
StopAsync(CancellationToken.None).ContinueWith(_ =>
|
||||||
{
|
{
|
||||||
StartAsync(CancellationToken.None);
|
StartAsync(CancellationToken.None);
|
||||||
@ -49,14 +59,13 @@ public class ScheduleSyncService : IHostedService, IDisposable
|
|||||||
|
|
||||||
private void ScheduleNextRun()
|
private void ScheduleNextRun()
|
||||||
{
|
{
|
||||||
var cronExpression = _generalConfigMonitor.CurrentValue.ScheduleSettings?.CronUpdateSchedule;
|
if (string.IsNullOrEmpty(_cronUpdate))
|
||||||
if (string.IsNullOrEmpty(cronExpression))
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Cron expression is not set. The scheduled task will not run.");
|
_logger.LogWarning("Cron expression is not set. The scheduled task will not run.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextRunTime = CronExpression.Parse(cronExpression).GetNextOccurrence(DateTimeOffset.Now, TimeZoneInfo.Local);
|
var nextRunTime = CronExpression.Parse(_cronUpdate).GetNextOccurrence(DateTimeOffset.Now, TimeZoneInfo.Local);
|
||||||
|
|
||||||
if (!nextRunTime.HasValue)
|
if (!nextRunTime.HasValue)
|
||||||
{
|
{
|
||||||
@ -112,7 +121,7 @@ public class ScheduleSyncService : IHostedService, IDisposable
|
|||||||
StopAsync(CancellationToken.None).GetAwaiter().GetResult();
|
StopAsync(CancellationToken.None).GetAwaiter().GetResult();
|
||||||
_timer?.Dispose();
|
_timer?.Dispose();
|
||||||
ScheduleSyncManager.OnForceSyncRequested -= OnForceSyncRequested;
|
ScheduleSyncManager.OnForceSyncRequested -= OnForceSyncRequested;
|
||||||
ScheduleSyncManager.OnUpdateIntervalRequested -= OnUpdateIntervalRequested;
|
_onChangeUpdateCron?.Dispose();
|
||||||
_cancellationTokenSource.Dispose();
|
_cancellationTokenSource.Dispose();
|
||||||
|
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
Reference in New Issue
Block a user