/// <summary>
        /// Creates LiteDB distributed lock
        /// </summary>
        /// <param name="resource">Lock resource</param>
        /// <param name="timeout">Lock timeout</param>
        /// <param name="database">Lock database</param>
        /// <param name="storageOptions">Database options</param>
        /// <exception cref="DistributedLockTimeoutException">Thrown if lock is not acuired within the timeout</exception>
        /// <exception cref="LiteDbDistributedLockException">Thrown if other LiteDB specific issue prevented the lock to be acquired</exception>
        public LiteDbDistributedLock(string resource, TimeSpan timeout, HangfireDbContext database, LiteDbStorageOptions storageOptions)
        {
            _resource       = resource ?? throw new ArgumentNullException(nameof(resource));
            _database       = database ?? throw new ArgumentNullException(nameof(database));
            _storageOptions = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));

            if (string.IsNullOrEmpty(resource))
            {
                throw new ArgumentException($@"The {nameof(resource)} cannot be empty", nameof(resource));
            }
            if (timeout.TotalSeconds > int.MaxValue)
            {
                throw new ArgumentException($"The timeout specified is too large. Please supply a timeout equal to or less than {int.MaxValue} seconds", nameof(timeout));
            }

            if (!AcquiredLocks.Value.ContainsKey(_resource) || AcquiredLocks.Value[_resource] == 0)
            {
                Cleanup();
                Acquire(timeout);
                AcquiredLocks.Value[_resource] = 1;
                StartHeartBeat();
            }
            else
            {
                AcquiredLocks.Value[_resource]++;
            }
        }
#pragma warning disable 1591
        public LiteDbConnection(
            HangfireDbContext database,
            LiteDbStorageOptions storageOptions,
            PersistentJobQueueProviderCollection queueProviders)
        {
            Database        = database ?? throw new ArgumentNullException(nameof(database));
            _storageOptions = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));
            _queueProviders = queueProviders ?? throw new ArgumentNullException(nameof(queueProviders));
        }
Пример #3
0
        /// <summary>
        /// Constructs Job Storage by database connection string and options
        /// </summary>
        /// <param name="connectionString">LiteDB connection string</param>
        /// <param name="storageOptions">Storage options</param>
        public LiteDbStorage(string connectionString, LiteDbStorageOptions storageOptions)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            _connectionString = connectionString;
            _storageOptions   = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));

            Connection = HangfireDbContext.Instance(connectionString, storageOptions.Prefix);
            Connection.Init(_storageOptions);
            var defaultQueueProvider = new LiteDbJobQueueProvider(_storageOptions);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="nameOrConnectionString"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IGlobalConfiguration <LiteDbStorage> UseLiteDbStorage(
            [NotNull] this IGlobalConfiguration configuration,
            [NotNull] string nameOrConnectionString,
            LiteDbStorageOptions options = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException(nameof(nameOrConnectionString));
            }
            if (options == null)
            {
                options = new LiteDbStorageOptions();
            }
            var storage = new LiteDbStorage(nameOrConnectionString, options);

            return(configuration.UseStorage(storage));
        }
 /// <summary>
 /// Initializes intial collections schema for Hangfire
 /// </summary>
 public void Init(LiteDbStorageOptions storageOptions)
 {
     StorageOptions = storageOptions;
 }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="storageOptions"></param>
 public LiteDbJobQueue(HangfireDbContext connection, LiteDbStorageOptions storageOptions)
 {
     _storageOptions = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));
     _connection     = connection ?? throw new ArgumentNullException(nameof(connection));
 }
Пример #7
0
 /// <summary>
 /// Initializes intial collections schema for Hangfire
 /// </summary>
 public void Init(LiteDbStorageOptions storageOptions)
 {
     //var migrationManager = new LiteDbStorageOptions(storageOptions);
     //migrationManager.Migrate(this);
 }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="storageOptions"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public LiteDbJobQueueProvider(LiteDbStorageOptions storageOptions)
 {
     _storageOptions = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));
 }