Esempio n. 1
0
        /// <summary>
        /// Initializes SqlServerStorage from the provided SqlServerStorageOptions and either the provided connection
        /// string or the connection string with provided name pulled from the application config file.       
        /// </summary>
        /// <param name="nameOrConnectionString">Either a SQL Server connection string or the name of 
        /// a SQL Server connection string located in the connectionStrings node in the application config</param>
        /// <param name="options"></param>
        /// <exception cref="ArgumentNullException"><paramref name="nameOrConnectionString"/> argument is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="nameOrConnectionString"/> argument is neither 
        /// a valid SQL Server connection string nor the name of a connection string in the application
        /// config file.</exception>
        public SqlServerStorage(string nameOrConnectionString, SqlServerStorageOptions options)
        {
            if (nameOrConnectionString == null) throw new ArgumentNullException("nameOrConnectionString");
            if (options == null) throw new ArgumentNullException("options");

            _options = options;

            if (IsConnectionString(nameOrConnectionString))
            {
                _connectionString = nameOrConnectionString;
            }
            else if (IsConnectionStringInConfiguration(nameOrConnectionString))
            {
                _connectionString = ConfigurationManager.ConnectionStrings[nameOrConnectionString].ConnectionString;
            }
            else
            {
                throw new ArgumentException(
                    string.Format("Could not find connection string with name '{0}' in application config file",
                                  nameOrConnectionString));
            }

            if (options.PrepareSchemaIfNecessary)
            {
                using (var connection = CreateAndOpenConnection())
                {
                    SqlServerObjectsInstaller.Install(connection);
                }
            }

            InitializeQueueProviders();
        }
Esempio n. 2
0
      public void ConfigureHangFire(IAppBuilder app)
      {
         var storageOptions = new SqlServerStorageOptions
         {
            InvisibilityTimeout = TimeSpan.FromHours(2),
            QueuePollInterval = TimeSpan.FromMinutes(15.0)
         };
         GlobalConfiguration.Configuration
            .UseSqlServerStorage("TrainingManagerDb", storageOptions);

         // case msmq installed
         /*GlobalConfiguration.Configuration
            .UseSqlServerStorage("TrainingManagerDb")
            .UseMsmqQueues(@".\hangfire-{0}");*/



         var dashboardOptions = new DashboardOptions
         {
            AuthorizationFilters = new[] { new AuthorizationFilter { Roles = AppConstants.UserRole.Administrator } }
         };
         app.UseHangfireDashboard("/hangfire", dashboardOptions);


         var jobServerOptions = new BackgroundJobServerOptions
         {
            WorkerCount = 1
         };
         app.UseHangfireServer(jobServerOptions);

         RecurringJob.AddOrUpdate(() => UpdateDaemon.ScheduledCatalogsUpdate(), Cron.Hourly);
      }
Esempio n. 3
0
		private void ConfigureHangfire(IApplicationBuilder app)
		{
			const string queueName = @".\private$\hangfire_health";

			if (!MessageQueue.Exists(queueName))
			{
				var queue = MessageQueue.Create(queueName, true);
				queue.SetPermissions("Administrators", MessageQueueAccessRights.FullControl);
			}

			var options = new SqlServerStorageOptions
			{
				PrepareSchemaIfNecessary = true
			};

			GlobalConfiguration.Configuration
				.UseSqlServerStorage("Server=.\\sqlexpress;Database=HangfireHealth;Trusted_Connection=True;MultipleActiveResultSets=true", options)
				.UseMsmqQueues(queueName)
				.UseDIActivator(app.ApplicationServices)
				.UseDashboardMetric(DashboardMetrics.ScheduledCount)
				.UseDashboardMetric(DashboardMetrics.RetriesCount)
				.UseDashboardMetric(DashboardMetrics.ProcessingCount)
				.UseDashboardMetric(DashboardMetrics.SucceededCount)
				.UseDashboardMetric(DashboardMetrics.FailedCount)
				.UseDashboardMetric(DashboardMetrics.AwaitingCount);

			app.UseHangfireServer();
			app.UseHangfireDashboard("/hangfire", new DashboardOptions
			{
				AuthorizationFilters = new[] { new HangfireAuthorizationFilter() }
			});
		}
        public SqlServerJobQueue([NotNull] SqlServerStorage storage, SqlServerStorageOptions options)
        {
            if (storage == null) throw new ArgumentNullException("storage");
            if (options == null) throw new ArgumentNullException("options");

            _storage = storage;
            _options = options;
        }
Esempio n. 5
0
        public SqlServerJobQueue(IDbConnection connection, SqlServerStorageOptions options)
        {
            if (options == null) throw new ArgumentNullException("options");
            if (connection == null) throw new ArgumentNullException("connection");

            _options = options;
            _connection = connection;
        }
        public SqlServerJobQueueProvider(SqlServerStorageOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _options = options;
        }
        public static SqlServerStorage UseSqlServerStorage(
            this IBootstrapperConfiguration configuration,
            string nameOrConnectionString,
            SqlServerStorageOptions options)
        {
            var storage = new SqlServerStorage(nameOrConnectionString, options);
            configuration.UseStorage(storage);

            return storage;
        }
Esempio n. 8
0
        public static SqlServerStorage UseSqlServerStorage(
            this IBootstrapperConfiguration configuration,
            string nameOrConnectionString,
            SqlServerStorageOptions options)
        {
            var storage = new SqlServerStorage(nameOrConnectionString, options);

            configuration.UseStorage(storage);

            return(storage);
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlServerStorage"/> class with
        /// explicit instance of the <see cref="SqlConnection"/> class that will be used
        /// to query the data.
        /// </summary>
        /// <param name="existingConnection">Existing connection</param>
        public SqlServerStorage([NotNull] SqlConnection existingConnection)
        {
            if (existingConnection == null)
            {
                throw new ArgumentNullException("existingConnection");
            }

            _existingConnection = existingConnection;
            _options            = new SqlServerStorageOptions();

            InitializeQueueProviders();
        }
Esempio n. 10
0
        public SqlServerJobQueue(IDbConnection connection, SqlServerStorageOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            _options    = options;
            _connection = connection;
        }
Esempio n. 11
0
        public SqlServerJobQueue([NotNull] SqlServerStorage storage, SqlServerStorageOptions options)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _storage = storage;
            _options = options;
        }
Esempio n. 12
0
        public SqlServerJobQueueProvider([NotNull] SqlServerStorage storage, [NotNull] SqlServerStorageOptions options)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _jobQueue      = new SqlServerJobQueue(storage, options);
            _monitoringApi = new SqlServerJobQueueMonitoringApi(storage);
        }
Esempio n. 13
0
        public void Configuration(IAppBuilder app)
        {
            app.UseErrorPage();
            app.UseWelcomePage("/");
            app.UseHangfire(config =>
            {
                var options = new SqlServerStorageOptions { QueuePollInterval = TimeSpan.FromSeconds(1) };
                config.UseSqlServerStorage("DataContext", options).UseMsmqQueues(@".\private$\hangfire-0");
                config.UseServer();
            });

            RecurringJob.AddOrUpdate(() => CleanJob.Execute(), System.Configuration.ConfigurationManager.AppSettings["CleanJobSchedule"]);
            RecurringJob.AddOrUpdate(() => LogsCompactionJob.Execute(), System.Configuration.ConfigurationManager.AppSettings["LogCompactionJobSchedule"]);
            RecurringJob.AddOrUpdate(() => PackageCleanupJob.Execute(), System.Configuration.ConfigurationManager.AppSettings["PackageCleanupJob"]);
        }
Esempio n. 14
0
        /// <summary>
        /// Initializes SqlServerStorage from the provided SqlServerStorageOptions and either the provided connection
        /// string or the connection string with provided name pulled from the application config file.
        /// </summary>
        /// <param name="nameOrConnectionString">Either a SQL Server connection string or the name of
        /// a SQL Server connection string located in the connectionStrings node in the application config</param>
        /// <param name="options"></param>
        /// <exception cref="ArgumentNullException"><paramref name="nameOrConnectionString"/> argument is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="nameOrConnectionString"/> argument is neither
        /// a valid SQL Server connection string nor the name of a connection string in the application
        /// config file.</exception>
        public SqlServerStorage(string nameOrConnectionString, SqlServerStorageOptions options)
        {
            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException(nameof(nameOrConnectionString));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _connectionString = GetConnectionString(nameOrConnectionString);
            _options          = options;

            Initialize();
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlServerStorage"/> class with
        /// explicit instance of the <see cref="DbConnection"/> class that will be used
        /// to query the data, with the given options.
        /// </summary>
        public SqlServerStorage([NotNull] DbConnection existingConnection, [NotNull] SqlServerStorageOptions options)
        {
            if (existingConnection == null)
            {
                throw new ArgumentNullException(nameof(existingConnection));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _existingConnection = existingConnection;
            _options            = options;

            Initialize();
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlServerStorage"/> class with
        /// a connection factory <see cref="Func{DbConnection}"/> class that will be invoked
        /// to create new database connections for querying the data.
        /// </summary>
        public SqlServerStorage([NotNull] Func <DbConnection> connectionFactory, [NotNull] SqlServerStorageOptions options)
        {
            if (connectionFactory == null)
            {
                throw new ArgumentNullException(nameof(connectionFactory));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _connectionFactory = connectionFactory;
            _options           = options;

            Initialize();
        }
Esempio n. 17
0
        public void ConfigureHangfire(IAppBuilder app)
        {
            var options = new SqlServerStorageOptions
            {
                // Set to true by default, but the option is there for later use.
                PrepareSchemaIfNecessary = true,
                // Default is 15 secs, options is there for later use.
                QueuePollInterval = TimeSpan.FromSeconds(15),
                // Default is 30 mins, options is there for later use.
                InvisibilityTimeout = TimeSpan.FromMinutes(30)
            };

            GlobalConfiguration.Configuration.UseSqlServerStorage("HangFireDb", options);
            app.UseHangfireDashboard();
            app.UseHangfireServer();
        }
        private JobStorage CreateJobStorage(Stage stage)
        {
            JobStorage result = null;

            if (string.Equals(_options.JobStorageType, "SqlServer", StringComparison.OrdinalIgnoreCase))
            {
                var sqlServerStorageOptions = new SqlServerStorageOptions
                {
                    PrepareSchemaIfNecessary = stage == Stage.ConfigureDatabase,
                    QueuePollInterval = TimeSpan.FromSeconds(60) /* Default is 15 seconds */
                };

                result = new SqlServerStorage(_options.DatabaseConnectionStringName, sqlServerStorageOptions);
            }
            else if (string.Equals(_options.JobStorageType, "Memory", StringComparison.OrdinalIgnoreCase))
            {
                result = new MemoryStorage();
            }

            return result;
        }
Esempio n. 19
0
        /// <summary>
        /// Initializes SqlServerStorage from the provided SqlServerStorageOptions and either the provided connection
        /// string or the connection string with provided name pulled from the application config file.
        /// </summary>
        /// <param name="nameOrConnectionString">Either a SQL Server connection string or the name of
        /// a SQL Server connection string located in the connectionStrings node in the application config</param>
        /// <param name="options"></param>
        /// <exception cref="ArgumentNullException"><paramref name="nameOrConnectionString"/> argument is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="nameOrConnectionString"/> argument is neither
        /// a valid SQL Server connection string nor the name of a connection string in the application
        /// config file.</exception>
        public SqlServerStorage(string nameOrConnectionString, SqlServerStorageOptions options)
        {
            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException("nameOrConnectionString");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _options = options;

            if (IsConnectionString(nameOrConnectionString))
            {
                _connectionString = nameOrConnectionString;
            }
            else if (IsConnectionStringInConfiguration(nameOrConnectionString))
            {
                _connectionString = ConfigurationManager.ConnectionStrings[nameOrConnectionString].ConnectionString;
            }
            else
            {
                throw new ArgumentException(
                          string.Format("Could not find connection string with name '{0}' in application config file",
                                        nameOrConnectionString));
            }

            if (options.PrepareSchemaIfNecessary)
            {
                using (var connection = CreateAndOpenConnection())
                {
                    SqlServerObjectsInstaller.Install(connection);
                }
            }

            var defaultQueueProvider = new SqlServerJobQueueProvider(options);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
Esempio n. 20
0
        /// <summary>
        /// Initializes SqlServerStorage from the provided SqlServerStorageOptions and either the provided connection
        /// string or the connection string with provided name pulled from the application config file.
        /// </summary>
        /// <param name="nameOrConnectionString">Either a SQL Server connection string or the name of
        /// a SQL Server connection string located in the connectionStrings node in the application config</param>
        /// <param name="options"></param>
        /// <exception cref="ArgumentNullException"><paramref name="nameOrConnectionString"/> argument is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="nameOrConnectionString"/> argument is neither
        /// a valid SQL Server connection string nor the name of a connection string in the application
        /// config file.</exception>
        public SqlServerStorage(string nameOrConnectionString, SqlServerStorageOptions options)
        {
            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException(nameof(nameOrConnectionString));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _connectionString = GetConnectionString(nameOrConnectionString);
            _options          = options;

            if (options.PrepareSchemaIfNecessary)
            {
                using (var connection = CreateAndOpenConnection())
                {
                    SqlServerObjectsInstaller.Install(connection, options.SchemaName);
                }
            }

            InitializeQueueProviders();
        }
Esempio n. 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqlServerStorage"/> class with
 /// explicit instance of the <see cref="DbConnection"/> class that will be used
 /// to query the data, with the given options.
 /// </summary>
 public SqlServerStorage([NotNull] DbConnection existingConnection, [NotNull] SqlServerStorageOptions options)
     : this(existingConnection, options, null)
 {
 }
Esempio n. 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlServerStorage"/> class with
        /// explicit instance of the <see cref="SqlConnection"/> class that will be used
        /// to query the data.
        /// </summary>
        /// <param name="existingConnection">Existing connection</param>
        public SqlServerStorage([NotNull] SqlConnection existingConnection)
        {
            if (existingConnection == null) throw new ArgumentNullException("existingConnection");

            _existingConnection = existingConnection;
            _options = new SqlServerStorageOptions();

            InitializeQueueProviders();
        }
Esempio n. 23
0
        public SqlServerJobQueueProvider(SqlServerStorageOptions options)
        {
            if (options == null) throw new ArgumentNullException("options");

            _options = options;
        }