private void Initialize() { if (_options.PrepareSchemaIfNecessary && Transaction == null) { UseConnection(null, connection => { SqlServerObjectsInstaller.Install(connection, _options.SchemaName); }); } InitializeQueueProviders(); }
private void Initialize() { if (_options.PrepareSchemaIfNecessary) { UseConnection(null, connection => { SqlServerObjectsInstaller.Install(connection, _options.SchemaName, _options.EnableHeavyMigrations); }); } InitializeQueueProviders(); }
private void Initialize() { _escapedSchemaName = _options.SchemaName.Replace("]", "]]"); if (_options.PrepareSchemaIfNecessary) { var log = LogProvider.GetLogger(typeof(SqlServerObjectsInstaller)); const int RetryAttempts = 3; log.Info("Start installing Hangfire SQL objects..."); Exception lastException = null; for (var i = 0; i < RetryAttempts; i++) { try { UseConnection(null, connection => { SqlServerObjectsInstaller.Install(connection, _options.SchemaName, _options.TablePrefix, _options.EnableHeavyMigrations); }); lastException = null; break; } catch (DbException ex) { lastException = ex; log.WarnException("An exception occurred while trying to perform the migration." + (i < RetryAttempts - 1 ? " Retrying..." : ""), ex); } } if (lastException != null) { log.WarnException("Was unable to perform the Hangfire schema migration due to an exception. Ignore this message unless you've just installed or upgraded Hangfire.", lastException); } else { log.Info("Hangfire SQL objects installed."); } } ValidateTablePrefix(); InitializeQueueProviders(); }
/// <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); }
/// <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(); }