diff --git a/src/api/src/application/Yoma.Core.Api/Controllers/KeycloakController.cs b/src/api/src/application/Yoma.Core.Api/Controllers/KeycloakController.cs index be6a74983..85b48decf 100644 --- a/src/api/src/application/Yoma.Core.Api/Controllers/KeycloakController.cs +++ b/src/api/src/application/Yoma.Core.Api/Controllers/KeycloakController.cs @@ -224,7 +224,7 @@ private async Task UpdateUserProfile(WebhookRequestEventType type, KeycloakWebho //updated here after email verification a login event is raised userRequest.EmailConfirmed = kcUser.EmailVerified; - userRequest.DateLastLogin = DateTime.Now; + userRequest.DateLastLogin = DateTimeOffset.UtcNow; try { diff --git a/src/api/src/domain/Yoma.Core.Domain/Entity/Services/OrganizationBackgroundService.cs b/src/api/src/domain/Yoma.Core.Domain/Entity/Services/OrganizationBackgroundService.cs index 311bf9d42..581187cf7 100644 --- a/src/api/src/domain/Yoma.Core.Domain/Entity/Services/OrganizationBackgroundService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/Entity/Services/OrganizationBackgroundService.cs @@ -63,7 +63,7 @@ public OrganizationBackgroundService(ILogger logg public async Task ProcessDeclination() { const string lockIdentifier = "organization_process_declination"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -71,12 +71,15 @@ public async Task ProcessDeclination() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing organization declination"); var statusDeclinationIds = Statuses_Declination.Select(o => _organizationStatusService.GetByName(o.ToString()).Id).ToList(); var statusDeclinedId = _organizationStatusService.GetByName(OrganizationStatus.Declined.ToString()).Id; - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _organizationRepository.Query(true).Where(o => statusDeclinationIds.Contains(o.StatusId) && o.DateModified <= DateTimeOffset.UtcNow.AddDays(-_scheduleJobOptions.OrganizationDeclinationIntervalInDays)) @@ -129,7 +132,7 @@ public async Task ProcessDeclination() } } - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } } @@ -148,7 +151,7 @@ public async Task ProcessDeclination() public async Task ProcessDeletion() { const string lockIdentifier = "organization_process_deletion"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -156,12 +159,15 @@ public async Task ProcessDeletion() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing organization deletion"); var statusDeletionIds = Statuses_Deletion.Select(o => _organizationStatusService.GetByName(o.ToString()).Id).ToList(); var statusDeletedId = _organizationStatusService.GetByName(OrganizationStatus.Deleted.ToString()).Id; - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _organizationRepository.Query().Where(o => statusDeletionIds.Contains(o.StatusId) && o.DateModified <= DateTimeOffset.UtcNow.AddDays(-_scheduleJobOptions.OrganizationDeletionIntervalInDays)) @@ -179,7 +185,7 @@ public async Task ProcessDeletion() await _organizationRepository.Update(items); - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } _logger.LogInformation("Processed organization deletion"); @@ -198,13 +204,15 @@ public async Task ProcessDeletion() public async Task SeedLogoAndDocuments() { const string lockIdentifier = "organization_seed_logos_and_documents"; - var dateTimeNow = DateTime.Now; var lockDuration = TimeSpan.FromHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours) + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); try { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + if (!_appSettings.TestDataSeedingEnvironmentsAsEnum.HasFlag(_environmentProvider.Environment)) { _logger.LogInformation("Organization logo and document seeding skipped for environment '{environment}'", _environmentProvider.Environment); diff --git a/src/api/src/domain/Yoma.Core.Domain/Entity/Services/UserBackgroundService.cs b/src/api/src/domain/Yoma.Core.Domain/Entity/Services/UserBackgroundService.cs index 8adddecce..c7509e1b3 100644 --- a/src/api/src/domain/Yoma.Core.Domain/Entity/Services/UserBackgroundService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/Entity/Services/UserBackgroundService.cs @@ -43,13 +43,15 @@ public UserBackgroundService(ILogger logger, public async Task SeedPhotos() { const string lockIdentifier = "user_seed_photos"; - var dateTimeNow = DateTime.Now; var lockDuration = TimeSpan.FromHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours) + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); try { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + if (!_appSettings.TestDataSeedingEnvironmentsAsEnum.HasFlag(_environmentProvider.Environment)) { _logger.LogInformation("User image seeding seeding skipped for environment '{environment}'", _environmentProvider.Environment); diff --git a/src/api/src/domain/Yoma.Core.Domain/Lookups/Services/SkillService.cs b/src/api/src/domain/Yoma.Core.Domain/Lookups/Services/SkillService.cs index a35f75491..f03537343 100644 --- a/src/api/src/domain/Yoma.Core.Domain/Lookups/Services/SkillService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/Lookups/Services/SkillService.cs @@ -106,13 +106,15 @@ public SkillSearchResults Search(SkillSearchFilter filter) public async Task SeedSkills(bool onStartupInitialSeeding) { const string lockIdentifier = "skill_seed"; - var dateTimeNow = DateTime.Now; var lockDuration = TimeSpan.FromHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours) + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); try { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + try { if (onStartupInitialSeeding && _skillRepository.Query().Any()) diff --git a/src/api/src/domain/Yoma.Core.Domain/MyOpportunity/Services/MyOpportunityBackgroundService.cs b/src/api/src/domain/Yoma.Core.Domain/MyOpportunity/Services/MyOpportunityBackgroundService.cs index 1f85cdfbb..f148a3ff1 100644 --- a/src/api/src/domain/Yoma.Core.Domain/MyOpportunity/Services/MyOpportunityBackgroundService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/MyOpportunity/Services/MyOpportunityBackgroundService.cs @@ -69,7 +69,7 @@ public MyOpportunityBackgroundService(ILogger lo public async Task ProcessVerificationRejection() { const string lockIdentifier = "myopportunity_process_verification_rejection"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -77,12 +77,15 @@ public async Task ProcessVerificationRejection() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing 'my' opportunity verification rejection"); var statusRejectedId = _myOpportunityVerificationStatusService.GetByName(VerificationStatus.Rejected.ToString()).Id; var statusRejectableIds = Statuses_Rejectable.Select(o => _myOpportunityVerificationStatusService.GetByName(o.ToString()).Id).ToList(); - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _myOpportunityRepository.Query().Where(o => o.VerificationStatusId.HasValue && statusRejectableIds.Contains(o.VerificationStatusId.Value) && o.DateModified <= DateTimeOffset.UtcNow.AddDays(-_scheduleJobOptions.MyOpportunityRejectionIntervalInDays)) @@ -140,7 +143,7 @@ public async Task ProcessVerificationRejection() } } - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } _logger.LogInformation("Processed 'my' opportunity verification rejection"); @@ -159,13 +162,15 @@ public async Task ProcessVerificationRejection() public async Task SeedPendingVerifications() { const string lockIdentifier = "myopportunity_seed_pending_verifications]"; - var dateTimeNow = DateTime.Now; var lockDuration = TimeSpan.FromHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours) + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); try { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + if (!_appSettings.TestDataSeedingEnvironmentsAsEnum.HasFlag(_environmentProvider.Environment)) { _logger.LogInformation("Pending verification seeding skipped for environment '{environment}'", _environmentProvider.Environment); diff --git a/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityBackgroundService.cs b/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityBackgroundService.cs index 892dbfbdd..08c350e93 100644 --- a/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityBackgroundService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityBackgroundService.cs @@ -54,7 +54,7 @@ public OpportunityBackgroundService(ILogger logger public async Task ProcessExpiration() { const string lockIdentifier = "opporrtunity_process_expiration"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -62,12 +62,15 @@ public async Task ProcessExpiration() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing opportunity expiration"); var statusExpiredId = _opportunityStatusService.GetByName(Status.Expired.ToString()).Id; var statusExpirableIds = Statuses_Expirable.Select(o => _opportunityStatusService.GetByName(o.ToString()).Id).ToList(); - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _opportunityRepository.Query().Where(o => statusExpirableIds.Contains(o.StatusId) && o.DateEnd.HasValue && o.DateEnd.Value <= DateTimeOffset.UtcNow).OrderBy(o => o.DateEnd).Take(_scheduleJobOptions.OpportunityExpirationBatchSize).ToList(); @@ -86,7 +89,7 @@ public async Task ProcessExpiration() await SendEmail(items, EmailType.Opportunity_Expiration_Expired); - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } _logger.LogInformation("Processed opportunity expiration"); @@ -105,13 +108,14 @@ public async Task ProcessExpiration() public async Task ProcessExpirationNotifications() { const string lockIdentifier = "opporrtunity_process_expiration_notifications"; - var dateTimeNow = DateTime.Now; var lockDuration = TimeSpan.FromHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours) + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); try { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); _logger.LogInformation("Processing opportunity expiration notifications"); @@ -142,7 +146,7 @@ public async Task ProcessExpirationNotifications() public async Task ProcessDeletion() { const string lockIdentifier = "opporrtunity_process_deletion"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -150,12 +154,15 @@ public async Task ProcessDeletion() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing opportunity deletion"); var statusDeletionIds = Statuses_Deletion.Select(o => _opportunityStatusService.GetByName(o.ToString()).Id).ToList(); var statusDeletedId = _opportunityStatusService.GetByName(Status.Deleted.ToString()).Id; - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { { var items = _opportunityRepository.Query().Where(o => statusDeletionIds.Contains(o.StatusId) && @@ -174,7 +181,7 @@ public async Task ProcessDeletion() await _opportunityRepository.Update(items); - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } } diff --git a/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityInfoService.cs b/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityInfoService.cs index c619765e5..733d895b0 100644 --- a/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityInfoService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/Opportunity/Services/OpportunityInfoService.cs @@ -139,7 +139,7 @@ public OpportunitySearchResultsInfo Search(OpportunitySearchFilter filter) cw.WriteRecords(result.Items); } - var fileName = $"Transactions_{DateTime.Now:yyyy-dd-M--HH-mm-ss}.csv"; + var fileName = $"Transactions_{DateTimeOffset.UtcNow:yyyy-dd-M--HH-mm-ss}.csv"; return (fileName, stream.ToArray()); } #endregion diff --git a/src/api/src/domain/Yoma.Core.Domain/Reward/Services/RewardBackgroundService.cs b/src/api/src/domain/Yoma.Core.Domain/Reward/Services/RewardBackgroundService.cs index 869e041f9..d1792f874 100644 --- a/src/api/src/domain/Yoma.Core.Domain/Reward/Services/RewardBackgroundService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/Reward/Services/RewardBackgroundService.cs @@ -54,7 +54,7 @@ public RewardBackgroundService(ILogger logger, public async Task ProcessWalletCreation() { const string lockIdentifier = "reward_process_wallet_creation"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.RewardWalletCreationScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -62,10 +62,13 @@ public async Task ProcessWalletCreation() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing Reward wallet creation"); var itemIdsToSkip = new List(); - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _walletService.ListPendingCreationSchedule(_scheduleJobOptions.RewardWalletCreationScheduleBatchSize, itemIdsToSkip); if (items.Count == 0) break; @@ -103,7 +106,7 @@ await _executionStrategyService.ExecuteInExecutionStrategyAsync(async () => itemIdsToSkip.Add(item.Id); } - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } } @@ -123,7 +126,7 @@ await _executionStrategyService.ExecuteInExecutionStrategyAsync(async () => public async Task ProcessRewardTransactions() { const string lockIdentifier = "reward_process_transactions"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.RewardTransactionScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -131,10 +134,13 @@ public async Task ProcessRewardTransactions() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing reward transactions"); var itemIdsToSkip = new List(); - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _rewardService.ListPendingTransactionSchedule(_scheduleJobOptions.RewardTransactionScheduleBatchSize, itemIdsToSkip); if (items.Count == 0) break; @@ -206,7 +212,7 @@ public async Task ProcessRewardTransactions() itemIdsToSkip.Add(item.Id); } - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } } diff --git a/src/api/src/domain/Yoma.Core.Domain/SSI/Services/SSIBackgroundService.cs b/src/api/src/domain/Yoma.Core.Domain/SSI/Services/SSIBackgroundService.cs index e1df3155d..37ccd43f9 100644 --- a/src/api/src/domain/Yoma.Core.Domain/SSI/Services/SSIBackgroundService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/SSI/Services/SSIBackgroundService.cs @@ -69,13 +69,15 @@ public SSIBackgroundService(ILogger logger, public async Task SeedSchemas() { const string lockIdentifier = "ssi_seed_schemas"; - var dateTimeNow = DateTime.Now; var lockDuration = TimeSpan.FromHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours) + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); try { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing SSI default schema seeding"); await SeedSchema(ArtifactType.JWS, @@ -102,7 +104,7 @@ await SeedSchema(ArtifactType.Indy, public async Task ProcessTenantCreation() { const string lockIdentifier = "ssi_process_tenant_creation"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.SSITenantCreationScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -110,10 +112,13 @@ public async Task ProcessTenantCreation() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing SSI tenant creation"); var itemIdsToSkip = new List(); - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _ssiTenantService.ListPendingCreationSchedule(_scheduleJobOptions.SSITenantCreationScheduleBatchSize, itemIdsToSkip); if (items.Count == 0) break; @@ -181,7 +186,7 @@ public async Task ProcessTenantCreation() itemIdsToSkip.Add(item.Id); } - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } } @@ -201,7 +206,7 @@ public async Task ProcessTenantCreation() public async Task ProcessCredentialIssuance() { const string lockIdentifier = "ssi_process_credential_issuance"; - var dateTimeNow = DateTime.Now; + var dateTimeNow = DateTimeOffset.UtcNow; var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.SSICredentialIssuanceScheduleMaxIntervalInHours); var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes); @@ -209,10 +214,13 @@ public async Task ProcessCredentialIssuance() { using (JobStorage.Current.GetConnection().AcquireDistributedLock(lockIdentifier, lockDuration)) { + _logger.LogInformation("Lock '{lockIdentifier}' acquired by {hostName} at {dateStamp}. Lock duration set to {lockDurationInMinutes} minutes", + lockIdentifier, Environment.MachineName, DateTimeOffset.UtcNow, lockDuration.TotalMinutes); + _logger.LogInformation("Processing SSI credential issuance"); var itemIdsToSkip = new List(); - while (executeUntil > DateTime.Now) + while (executeUntil > DateTimeOffset.UtcNow) { var items = _ssiCredentialService.ListPendingIssuanceSchedule(_scheduleJobOptions.SSICredentialIssuanceScheduleBatchSize, itemIdsToSkip); if (items.Count == 0) break; @@ -361,7 +369,7 @@ public async Task ProcessCredentialIssuance() itemIdsToSkip.Add(item.Id); } - if (executeUntil <= DateTime.Now) break; + if (executeUntil <= DateTimeOffset.UtcNow) break; } } diff --git a/src/api/src/infrastructure/Yoma.Core.Infrastructure.Keycloak/Client/KeycloakClient.cs b/src/api/src/infrastructure/Yoma.Core.Infrastructure.Keycloak/Client/KeycloakClient.cs index e171cdc13..b755a8f09 100644 --- a/src/api/src/infrastructure/Yoma.Core.Infrastructure.Keycloak/Client/KeycloakClient.cs +++ b/src/api/src/infrastructure/Yoma.Core.Infrastructure.Keycloak/Client/KeycloakClient.cs @@ -6,6 +6,7 @@ using Keycloak.AuthServices.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; +using System; using System.Net.Http.Headers; using System.Text; using Yoma.Core.Domain.Core; @@ -78,7 +79,7 @@ public bool AuthenticateWebhook(HttpContext httpContext) throw new ArgumentNullException(nameof(username)); var timeout = 15000; - var startTime = DateTime.Now; + var startTime = DateTimeOffset.UtcNow; UserRepresentation? kcUser = null; using (var usersApi = FS.Keycloak.RestApiClient.ClientFactory.ApiClientFactory.Create(_httpClient)) { @@ -87,7 +88,7 @@ public bool AuthenticateWebhook(HttpContext httpContext) kcUser = (await usersApi.GetUsersAsync(_keycloakAuthenticationOptions.Realm, username: username, exact: true)).SingleOrDefault(); if (kcUser != null) break; - if ((DateTime.Now - startTime).TotalMilliseconds >= timeout) break; + if ((DateTimeOffset.UtcNow - startTime).TotalMilliseconds >= timeout) break; Thread.Sleep(1000); } }