/// <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(); }