public MAMQPostgreSqlConnection(PostgreSqlStorage storage, IEnumerable <string>?queues, PostgreSqlStorageOptions options, string nameOrConnectionString) { const string postgresSqlConnectionTypeName = "Hangfire.PostgreSql.PostgreSqlConnection"; Type? type = typeof(PostgreSqlStorage) .Assembly .GetType(postgresSqlConnectionTypeName); Type?pgStorageType = typeof(PostgreSqlStorage); if (type == null) { throw new InvalidOperationException($"{postgresSqlConnectionTypeName} has not been loaded into the process."); } //BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; //FieldInfo field = pgStorageType.GetField("_existingConnection", bindFlags); //var func = pgStorageType.GetMethod("CreateAndOpenConnection", BindingFlags.Instance | BindingFlags.NonPublic); //var npgsqlConnection = func.Invoke(storage, new object[] { }); //var npgsqlConnection = field.GetValue(storage); // NpgsqlConnection connection, // PersistentJobQueueProviderCollection queueProviders, //PostgreSqlStorageOptions options) var npgsqlConnection = new NpgsqlConnection(nameOrConnectionString); npgsqlConnection.Open(); var connection = type.Assembly.CreateInstance(type.FullName, false, BindingFlags.Instance | BindingFlags.Public, null, new object[] { npgsqlConnection, storage.QueueProviders, options }, null, null) as JobStorageConnection; _postgreSqlConnection = connection ?? throw new InvalidOperationException($"Could not create an instance for {postgresSqlConnectionTypeName}"); _queues = queues; }
public static long GetRecurringJobCount([NotNull] this JobStorageConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } return(connection.GetSetCount("recurring-jobs")); }
public ConsoleStorage(IStorageConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } _connection = (JobStorageConnection)connection; }
private void DeleteAsAtom(JobStorageConnection jsc, string atomId) { var subatomIds = jsc.GetAllItemsFromSet(Atom.GenerateSubAtomKeys(atomId)); foreach (var subatomId in subatomIds) { var context = new StateChangeContext(JobStorage.Current, jsc, subatomId, new DeletedState()); _stateChanger.ChangeState(context); } }
public TagsStorage(JobStorage jobStorage) { var connection = jobStorage.GetConnection(); connection = connection ?? throw new ArgumentNullException(nameof(connection)); if (!(connection is JobStorageConnection jobStorageConnection)) { throw new NotSupportedException("Storage connection must implement JobStorageConnection"); } _connection = jobStorageConnection; }
public static List <RecurringJobDto> GetRecurringJobs( [NotNull] this JobStorageConnection connection, int startingFrom, int endingAt) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } var ids = connection.GetRangeFromSet("recurring-jobs", startingFrom, endingAt); return(GetRecurringJobDtos(connection, ids)); }
public ConsoleStorage(IStorageConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (!(connection is JobStorageConnection jobStorageConnection)) { throw new NotSupportedException("Storage connections must implement JobStorageConnection"); } _connection = jobStorageConnection; }
private JobStorageConnection GetJobStorageConnection() { JobStorageConnection storageConnection = null; using (IStorageConnection connection = JobStorage.Current.GetConnection()) { storageConnection = connection as JobStorageConnection; if (storageConnection == null) { throw new Exception("An error occurred getting the HangFire JobStorageConnection"); } } return(storageConnection); }
public MAMQSqlServerConnection(SqlServerStorage storage, IEnumerable <string>?queues) { const string sqlServerConnectionTypeName = "Hangfire.SqlServer.SqlServerConnection"; Type? type = typeof(SqlServerStorage) .Assembly .GetType(sqlServerConnectionTypeName); if (type == null) { throw new InvalidOperationException($"{sqlServerConnectionTypeName} has not been loaded into the process."); } var connection = type.Assembly.CreateInstance(type.FullName, false, BindingFlags.Instance | BindingFlags.Public, null, new[] { storage }, null, null) as JobStorageConnection; _sqlServerConnection = connection ?? throw new InvalidOperationException($"Could not create an instance for {sqlServerConnectionTypeName}"); _queues = queues; }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); GlobalConfiguration.Configuration.UseSqlServerStorage("EnscoHangfireIrmaConnection", new SqlServerStorageOptions { QueuePollInterval = TimeSpan.FromSeconds(10) }); app.UseHangfireDashboard(); app.UseHangfireServer(); // setup any schedule jobs for background processing using (JobStorageConnection connection = Hangfire.JobStorage.Current.GetConnection() as JobStorageConnection) { EnscoSchedulerService.ScheduleJobs(connection); OAPScheduler.ScheduleBarrierAuthorityTasks(connection); OAPScheduler.ScheduleOIMOversightReminderEmails(connection); } }
private static void SetTriggerInternal( IBackgroundJobClient client, JobStorageConnection connection, string triggerName) { var triggerKey = GenerateTriggerKey(triggerName); var jobIds = connection.GetAllItemsFromList(triggerKey); try { using var _ = connection.AcquireDistributedLock(triggerKey, TimeSpan.Zero); foreach (var jobId in jobIds) { client.ChangeState(jobId, new EnqueuedState()); } } catch (DistributedLockTimeoutException) { // Assume already run } }
public static bool CheckIfAtomIsFinished(this JobStorageConnection connection, string atomId) { var atomState = connection.GetStateData(atomId); return(atomState.Name == SucceededState.StateName); }
public static JobStorageTransaction CreateJobStorageTransaction(this JobStorageConnection jobStorageConnection) => (JobStorageTransaction)jobStorageConnection.CreateWriteTransaction();