/// <summary> /// Removes all jobs and creates new jobs for existing data sources /// </summary> /// <returns></returns> public async Task SyncDataSourceAndCreateJobsAsync() { using (var connection = JobStorage.Current.GetConnection()) { foreach (var recurringJob in connection.GetRecurringJobs()) { RecurringJob.RemoveIfExists(recurringJob.Id); } } using var systemSession = await _systemContext.StartSystemSessionAsync(); systemSession.StartTransaction(); // Clean old jobs var result = await _systemContext.GetTenantsAsync(systemSession); foreach (var ospDataSource in result.List) { RecurringJob.AddOrUpdate <ServiceHookJob>($"ServiceHook_{ospDataSource.TenantId}", job => job.Run(ospDataSource.TenantId, JobCancellationToken.Null), "*/15 * * * *"); RecurringJob.AddOrUpdate <AttributeValueAggregatorJob>($"AttributeValueAggregate_{ospDataSource.TenantId}", job => job.Run(ospDataSource.TenantId, JobCancellationToken.Null), Cron.Daily); RecurringJob.AddOrUpdate <EMailSenderJob>($"Notification_EMail_Sender_{ospDataSource.TenantId}", job => job.SendEMail(ospDataSource.TenantId, JobCancellationToken.Null), Cron.Minutely); } await systemSession.CommitTransactionAsync(); }
public async Task ImportCkAsync(string tenantId, string key, ScopeIdsDto scopeId, IJobCancellationToken cancellationToken) { try { if (scopeId == ScopeIdsDto.System) { throw new InvalidOperationException("Scope SYSTEM cannot be imported, because this scope is handled by system."); } Logger.Info($"Reading input file from cache for CK import to '{tenantId}'"); var tempFile = await GetTempFile(key); Logger.Info($"Starting import of file '{tempFile}'"); using var systemSession = await _systemContext.StartSystemSessionAsync(); systemSession.StartTransaction(); await _systemContext.ImportCkModelAsync(systemSession, tenantId, (ScopeIds)scopeId, tempFile, cancellationToken.ShutdownToken); await systemSession.CommitTransactionAsync(); await ClearCache(key); Logger.Info($"Import of file '{tempFile}' completed."); } catch (Exception e) { Logger.Error(e, "Import failed with error."); throw; } }
public async Task SetupAsync() { using var session = await _systemContext.StartSystemSessionAsync(); session.StartTransaction(); var version = await _systemContext.GetConfigurationAsync(session, IdentityServiceConstants.IdentitySchemaVersionKey, 0); if (version < IdentityServiceConstants.IdentitySchemaVersionValue) { await CreateClients(); await CreateUsersAndRoles(); await CreateApiScopes(); await CreateApiResources(); await CreateIdentityResources(); await CreateIdentityProvider(); await _systemContext.SetConfigurationAsync(session, IdentityServiceConstants.IdentitySchemaVersionKey, IdentityServiceConstants.IdentitySchemaVersionValue); } await session.CommitTransactionAsync(); }
public async Task SetupAsync() { using var session = await _systemContext.StartSystemSessionAsync(); session.StartTransaction(); var version = await _systemContext.GetConfigurationAsync(session, JobServiceConstants.JobServiceSchemaVersionKey, 0); if (version < JobServiceConstants.JobServiceSchemaVersionValue) { await CreateApiScopes(); await CreateApiResources(); await CreateClients(); await _systemContext.SetConfigurationAsync(session, JobServiceConstants.JobServiceSchemaVersionKey, JobServiceConstants.JobServiceSchemaVersionValue); } await session.CommitTransactionAsync(); }