public static void Start() { // Please, visit http://hangfire.io/ for details. // HangFire uses persistent data storage to store information // about jobs, queues, statistics, etc. // Default implementation uses SQL Server as a storage. You only // need to provide connection string to start using HangFire - // all database objects will be installed automatically. var storage = new SqlServerStorage( @"Server=.\sqlexpress;Database=HangFire.Sample;Trusted_Connection=True;"); storage.UseMsmqQueues(@".\Private$\hangfire{0}", "default", "critical"); JobStorage.Current = storage; // If your project infrastructure contains Redis server, you may // choose Redis job storage implementation (it is much faster). // To do this, type in your Package Manager Console window: // // Install-Package HangFire.Redis // // Then, uncomment the line below and set up your connection. // JobStorage.Current = new RedisStorage("localhost:6379", 3); // HangFire Server processes jobs while your application is being // performed. They are performed in a reliable way and your ASP.NET // application will never loose them. _server = new AspNetBackgroundJobServer(); //_server.Start(); }
public ExpirationManager(SqlServerStorage storage, TimeSpan checkInterval) { if (storage == null) throw new ArgumentNullException("storage"); _storage = storage; _checkInterval = checkInterval; }
public ExpirationManager(SqlServerStorage storage, TimeSpan checkInterval) { if (storage == null) { throw new ArgumentNullException("storage"); } _storage = storage; _checkInterval = checkInterval; }
public MsmqSqlServerStorageExtensionsFacts() { _storage = new SqlServerStorage( String.Empty, new SqlServerStorageOptions { PrepareSchemaIfNecessary = false }); }
public static void Main() { LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter( LogLevel.Info, false, false, true, ""); var sqlServerStorage = new SqlServerStorage( @"Server=.\sqlexpress;Database=HangFire.Sample;Trusted_Connection=True;"); sqlServerStorage.UseMsmqQueues(@".\Private$\hangfire{0}", "default", "critical"); JobStorage.Current = sqlServerStorage; //new RedisStorage("localhost:6379", 3); RecurringJob.AddOrUpdate(() => Console.WriteLine("Hello, world!"), Cron.Minutely); RecurringJob.AddOrUpdate("hourly", () => Console.WriteLine("Hello"), Cron.Hourly); var options = new BackgroundJobServerOptions { Queues = new[] { "critical", "default" } }; using (var server = new BackgroundJobServer(options)) { var count = 1; while (true) { var command = Console.ReadLine(); if (command == null || command.Equals("stop", StringComparison.OrdinalIgnoreCase)) { break; } if (command.Equals("start", StringComparison.OrdinalIgnoreCase)) { server.Start(); } if (command.StartsWith("add", StringComparison.OrdinalIgnoreCase)) { try { var workCount = int.Parse(command.Substring(4)); for (var i = 0; i < workCount; i++) { var number = i; BackgroundJob.Enqueue<Services>(x => x.Random(number)); } Console.WriteLine("Jobs enqueued."); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (command.StartsWith("static", StringComparison.OrdinalIgnoreCase)) { try { var workCount = int.Parse(command.Substring(7)); for (var i = 0; i < workCount; i++) { BackgroundJob.Enqueue(() => Console.WriteLine("Hello, {0}!", "world")); } Console.WriteLine("Jobs enqueued."); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (command.StartsWith("error", StringComparison.OrdinalIgnoreCase)) { var workCount = int.Parse(command.Substring(6)); for (var i = 0; i < workCount; i++) { BackgroundJob.Enqueue<Services>(x => x.Error()); } } if (command.StartsWith("args", StringComparison.OrdinalIgnoreCase)) { var workCount = int.Parse(command.Substring(5)); for (var i = 0; i < workCount; i++) { BackgroundJob.Enqueue<Services>(x => x.Args(Guid.NewGuid().ToString(), 14442, DateTime.UtcNow)); } } if (command.StartsWith("in", StringComparison.OrdinalIgnoreCase)) { var seconds = int.Parse(command.Substring(2)); var number = count++; BackgroundJob.Schedule<Services>(x => x.Random(number), TimeSpan.FromSeconds(seconds)); } if (command.StartsWith("cancelable", StringComparison.OrdinalIgnoreCase)) { var iterations = int.Parse(command.Substring(11)); BackgroundJob.Enqueue<Services>(x => x.Cancelable(iterations, JobCancellationToken.Null)); } if (command.StartsWith("delete", StringComparison.OrdinalIgnoreCase)) { var workCount = int.Parse(command.Substring(7)); for (var i = 0; i < workCount; i++) { var jobId = BackgroundJob.Enqueue<Services>(x => x.EmptyDefault()); BackgroundJob.Delete(jobId); } } if (command.StartsWith("fast", StringComparison.OrdinalIgnoreCase)) { try { var workCount = int.Parse(command.Substring(5)); Parallel.For(0, workCount, i => { if (i % 2 == 0) { BackgroundJob.Enqueue<Services>(x => x.EmptyCritical()); } else { BackgroundJob.Enqueue<Services>(x => x.EmptyDefault()); } }); Console.WriteLine("Jobs enqueued."); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }
public MsmqSqlServerStorageExtensionsFacts() { _storage = new SqlServerStorage( @"Server=.\sqlexpress;Database=TheDatabase;Trusted_Connection=True;", new SqlServerStorageOptions { PrepareSchemaIfNecessary = false }); }
public ExpirationManager(SqlServerStorage storage) : this(storage, TimeSpan.FromHours(1)) { }