private void OnAction(BackgroundJob backgroundJob, JobActionTiming timing) { using var dbContext = this.dbContextFactory.CreateDbContext(); var jobName = backgroundJob.GetJobName(); var jobActions = dbContext.JobActions .Where(y => y.JobName == jobName) .Where(y => y.Timing == timing) .Where(y => y.IsEnabled) .OrderBy(y => y.Order).ThenBy(y => y.JobName) .ToList(); if (jobActions.Any() == false) { return; } // Start a transaction scope so all transactions, including cross-database transactions are included using var transactionScope = new TransactionScope(); try { foreach (var ja in jobActions) { try { if (ja.Action.StartsWith(RecurringJobTriggerPrefix)) { this.TriggerRecurringJob(ja); } else { this.TriggerSqlCommand(ja); } } catch (Exception ex) { throw new JobActionFailedException(ja, ex); } } transactionScope.Complete(); } catch (Exception) { throw; } }