Files
hangfire-ravendb/examples/Hangfire.Raven.Examples.Console/Program.cs
T

53 lines
1.9 KiB
C#
Raw Normal View History

2015-10-16 16:07:20 -05:00
using System;
using Hangfire.Raven.Storage;
2015-10-16 16:07:20 -05:00
namespace Hangfire.Raven.Examples.Console
2015-10-16 16:07:20 -05:00
{
public static class Program
{
public static int x = 0;
public static void Main()
{
try {
// you can use Raven Storage and specify the connection string name
GlobalConfiguration.Configuration
.UseColouredConsoleLogProvider()
.UseRavenStorage("RavenDebug");
// you can use Raven Storage and specify the connection string and database name
//GlobalConfiguration.Configuration
// .UseColouredConsoleLogProvider()
// .UseRavenStorage("http://localhost:9090", "HangfireConsole");
2015-10-16 16:07:20 -05:00
// you can use Raven Embedded Storage which runs in memory!
//GlobalConfiguration.Configuration
// .UseColouredConsoleLogProvider()
// .UseEmbeddedRavenStorage();
2015-10-16 16:07:20 -05:00
//you have to create an instance of background job server at least once for background jobs to run
var client = new BackgroundJobServer();
2015-10-16 16:07:20 -05:00
// Run once
2016-12-08 21:16:09 -06:00
BackgroundJob.Enqueue(() => System.Console.WriteLine("Background Job: Hello, world!"));
BackgroundJob.Enqueue(() => Test());
// Run every minute
RecurringJob.AddOrUpdate(() => Test(), Cron.Minutely);
System.Console.WriteLine("Press Enter to exit...");
System.Console.ReadLine();
} catch (Exception ex) {
throw ex;
}
2015-10-16 16:07:20 -05:00
}
2015-10-18 01:39:08 -05:00
[AutomaticRetry(Attempts = 2, LogEvents = true, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public static void Test()
2015-10-16 16:07:20 -05:00
{
System.Console.WriteLine($"{x++} Cron Job: Hello, world!");
//throw new ArgumentException("fail");
2015-10-16 16:07:20 -05:00
}
}
}