Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public static long GetRecurringJobCount([NotNull] this JobStorageConnection connection)
 {
     if (connection == null)
     {
         throw new ArgumentNullException(nameof(connection));
     }
     return(connection.GetSetCount("recurring-jobs"));
 }
Exemplo n.º 3
0
        public ConsoleStorage(IStorageConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            _connection = (JobStorageConnection)connection;
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        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
            }
        }
Exemplo n.º 12
0
        public static bool CheckIfAtomIsFinished(this JobStorageConnection connection, string atomId)
        {
            var atomState = connection.GetStateData(atomId);

            return(atomState.Name == SucceededState.StateName);
        }
Exemplo n.º 13
0
 public static JobStorageTransaction CreateJobStorageTransaction(this JobStorageConnection jobStorageConnection)
 => (JobStorageTransaction)jobStorageConnection.CreateWriteTransaction();