Represents Hangfire storage options for MongoDB implementation
コード例 #1
0
		public static MongoStorage UseMongoStorage(this IBootstrapperConfiguration configuration,
			MongoClientSettings mongoClientSettings,
			string databaseName,
			MongoStorageOptions options)
		{
			MongoStorage storage = new MongoStorage(mongoClientSettings, databaseName, options);

			configuration.UseStorage(storage);

			return storage;
		}
コード例 #2
0
        public static MongoStorage UseMongoStorage(this IBootstrapperConfiguration configuration,
            string connectionString,
            string databaseName,
            MongoStorageOptions options)
        {
            MongoStorage storage = new MongoStorage(connectionString, databaseName, options);

            configuration.UseStorage(storage);

            return storage;
        }
コード例 #3
0
        public MongoConnection(HangfireDbContext database, MongoStorageOptions options, PersistentJobQueueProviderCollection queueProviders)
        {
            if (database == null)
                throw new ArgumentNullException("database");

            if (queueProviders == null)
                throw new ArgumentNullException("queueProviders");

            if (options == null)
                throw new ArgumentNullException("options");

            _database = database;
            _options = options;
            _queueProviders = queueProviders;
        }
コード例 #4
0
        /// <summary>
        /// Constructs Job Storage by database connection string, name andoptions
        /// </summary>
        /// <param name="connectionString">MongoDB connection string</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="options">Storage options</param>
        public MongoStorage(string connectionString, string databaseName, MongoStorageOptions options)
        {
            if (String.IsNullOrWhiteSpace(connectionString) == true)
                throw new ArgumentNullException("connectionString");

            if (String.IsNullOrWhiteSpace(databaseName) == true)
                throw new ArgumentNullException("databaseName");

            if (options == null)
                throw new ArgumentNullException("options");

            _connectionString = connectionString;
            _databaseName = databaseName;
            _options = options;

            Connection = new HangfireDbContext(connectionString, databaseName, options.Prefix);
            var defaultQueueProvider = new MongoJobQueueProvider(options);
            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
コード例 #5
0
 /// <summary>
 /// Creates new MongoDistributedLock
 /// </summary>
 /// <param name="resource"></param>
 /// <param name="timeout"></param>
 /// <param name="dbContext"></param>
 /// <param name="storageOptions"></param>
 /// <returns></returns>
 public virtual MongoDistributedLock CreateMongoDistributedLock(string resource, TimeSpan timeout, HangfireDbContext dbContext, MongoStorageOptions storageOptions)
 {
     return(new MongoDistributedLock($"Hangfire:{resource}", timeout, dbContext, storageOptions, DistributedLockMutex));
 }
コード例 #6
0
 /// <summary>
 /// Creates new MongoWriteOnlyTransaction instance
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="storageOptions"></param>
 /// <returns></returns>
 public virtual MongoWriteOnlyTransaction CreateMongoWriteOnlyTransaction(HangfireDbContext dbContext, MongoStorageOptions storageOptions)
 {
     return(new MongoWriteOnlyTransaction(dbContext, storageOptions));
 }
コード例 #7
0
 /// <summary>
 /// Creates MongoConnection instance
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="storageOptions"></param>
 /// <returns></returns>
 public virtual MongoConnection CreateMongoConnection(HangfireDbContext dbContext, MongoStorageOptions storageOptions)
 {
     return(new MongoConnection(dbContext, storageOptions));
 }
コード例 #8
0
 /// <summary>
 /// Creates MongoJobFetcher instance
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="storageOptions"></param>
 /// <returns></returns>
 public virtual MongoJobFetcher CreateMongoJobFetcher(HangfireDbContext dbContext, MongoStorageOptions storageOptions)
 {
     return(new MongoJobFetcher(dbContext, storageOptions, JobQueueSemaphore));
 }
コード例 #9
0
 /// <summary>
 /// Creates MongoExpirationManager instance
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="storageOptions"></param>
 /// <returns></returns>
 public virtual MongoExpirationManager CreateMongoExpirationManager(HangfireDbContext dbContext, MongoStorageOptions storageOptions)
 {
     return(new MongoExpirationManager(dbContext, storageOptions));
 }
コード例 #10
0
 /// <summary>
 /// Constructs expiration manager with one hour checking interval
 /// </summary>
 /// <param name="dbContext">MongoDB storage</param>
 /// <param name="options"></param>
 public MongoExpirationManager(HangfireDbContext dbContext, MongoStorageOptions options)
 {
     _dbContext     = dbContext;
     _options       = options;
     _checkInterval = options.JobExpirationCheckInterval;
 }
コード例 #11
0
 public MongoWriteOnlyTransaction(HangfireDbContext database,
                                  PersistentJobQueueProviderCollection queueProviders, MongoStorageOptions storageOptions)
 {
     _database       = database ?? throw new ArgumentNullException(nameof(database));
     _queueProviders = queueProviders ?? throw new ArgumentNullException(nameof(queueProviders));
     _storageOptions = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));
 }
コード例 #12
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
        {
            if (mongoClientSettings == null)
            {
                throw new ArgumentNullException(nameof(mongoClientSettings));
            }
            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            if (storageOptions == null)
            {
                throw new ArgumentNullException(nameof(storageOptions));
            }

            _mongoClientSettings = mongoClientSettings;
            _databaseName        = databaseName;
            _storageOptions      = storageOptions;

            _dbContext = new HangfireDbContext(mongoClientSettings, databaseName, _storageOptions.Prefix);

            using (var migrationManager = new MongoMigrationManager(storageOptions, _dbContext))
            {
                migrationManager.Migrate();
            }
        }
コード例 #13
0
 public MongoStorage(string connectionString, string databaseName, MongoStorageOptions storageOptions)
     : this(MongoClientSettings.FromConnectionString(connectionString), databaseName, storageOptions)
 {
 }
コード例 #14
0
 public MongoWriteOnlyTransaction(HangfireDbContext dbContext, MongoStorageOptions storageOptions)
 {
     _storageOptions   = storageOptions;
     DbContext         = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _jobsAddedToQueue = new HashSet <string>();
 }
コード例 #15
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
        {
            if (mongoClientSettings == null)
            {
                throw new ArgumentNullException(nameof(mongoClientSettings));
            }
            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            if (storageOptions == null)
            {
                throw new ArgumentNullException(nameof(storageOptions));
            }

            _mongoClientSettings = mongoClientSettings;
            _databaseName        = databaseName;
            _storageOptions      = storageOptions;

            _dbContext = new HangfireDbContext(mongoClientSettings, databaseName, _storageOptions.Prefix);

            if (_storageOptions.CheckConnection)
            {
                CheckConnection();
            }

            MongoMigrationManager.MigrateIfNeeded(storageOptions, _dbContext.Database);
        }
コード例 #16
0
 /// <summary>
 /// Constructs Job Storage by Mongo client settings, name and options
 /// </summary>
 /// <param name="mongoClientSettings">Client settings for MongoDB</param>
 /// <param name="databaseName">Database name</param>
 /// <param name="storageOptions">Storage options</param>
 public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
     : this(new MongoClient(mongoClientSettings), databaseName, storageOptions)
 {
 }
コード例 #17
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="options">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions options)
        {
            if (mongoClientSettings == null)
            {
                throw new ArgumentNullException(nameof(mongoClientSettings));
            }

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _mongoClientSettings = mongoClientSettings;
            _databaseName        = databaseName;
            _options             = options;

            Connection = new HangfireDbContext(mongoClientSettings, databaseName, options.Prefix);
            var defaultQueueProvider = new MongoJobQueueProvider(options);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
コード例 #18
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
        {
            _mongoClientSettings = mongoClientSettings ?? throw new ArgumentNullException(nameof(mongoClientSettings));
            _databaseName        = databaseName ?? throw new ArgumentNullException(nameof(databaseName));
            _storageOptions      = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentException("Please state a connection name", nameof(databaseName));
            }

            Connection = new HangfireDbContext(mongoClientSettings, databaseName, _storageOptions.Prefix);

            var migrationManager = new MongoMigrationManager(storageOptions);

            migrationManager.Migrate(Connection);

            var defaultQueueProvider = new MongoJobQueueProvider(_storageOptions);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }