2015-10-16 16:07:20 -05:00
|
|
|
using System;
|
code cleanup, migrated to dotnet core, builds for dnx46, dnx451, net45, net451, net452, net46, net461, netcoreapp1.0, netstandard1.6
2016-09-12 20:03:18 -05:00
|
|
|
using Hangfire.Raven.Storage;
|
2015-10-16 16:07:20 -05:00
|
|
|
|
2016-12-08 19:23:52 -06: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()
|
|
|
|
|
{
|
code cleanup, migrated to dotnet core, builds for dnx46, dnx451, net45, net451, net452, net46, net461, netcoreapp1.0, netstandard1.6
2016-09-12 20:03:18 -05:00
|
|
|
try {
|
2016-12-08 19:23:52 -06:00
|
|
|
// you can use Raven Storage and specify the connection string name
|
code cleanup, migrated to dotnet core, builds for dnx46, dnx451, net45, net451, net452, net46, net461, netcoreapp1.0, netstandard1.6
2016-09-12 20:03:18 -05:00
|
|
|
GlobalConfiguration.Configuration
|
|
|
|
|
.UseColouredConsoleLogProvider()
|
2016-12-08 19:23:52 -06:00
|
|
|
.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
|
|
|
|
code cleanup, migrated to dotnet core, builds for dnx46, dnx451, net45, net451, net452, net46, net461, netcoreapp1.0, netstandard1.6
2016-09-12 20:03:18 -05:00
|
|
|
// you can use Raven Embedded Storage which runs in memory!
|
|
|
|
|
//GlobalConfiguration.Configuration
|
|
|
|
|
// .UseColouredConsoleLogProvider()
|
|
|
|
|
// .UseEmbeddedRavenStorage();
|
2015-10-16 16:07:20 -05:00
|
|
|
|
code cleanup, migrated to dotnet core, builds for dnx46, dnx451, net45, net451, net452, net46, net461, netcoreapp1.0, netstandard1.6
2016-09-12 20:03:18 -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
|
|
|
|
2016-12-08 19:23:52 -06:00
|
|
|
// Run once
|
2016-12-08 21:16:09 -06:00
|
|
|
BackgroundJob.Enqueue(() => System.Console.WriteLine("Background Job: Hello, world!"));
|
2016-12-08 19:23:52 -06:00
|
|
|
|
|
|
|
|
BackgroundJob.Enqueue(() => Test());
|
|
|
|
|
|
|
|
|
|
// Run every minute
|
|
|
|
|
RecurringJob.AddOrUpdate(() => Test(), Cron.Minutely);
|
|
|
|
|
|
|
|
|
|
System.Console.WriteLine("Press Enter to exit...");
|
|
|
|
|
System.Console.ReadLine();
|
code cleanup, migrated to dotnet core, builds for dnx46, dnx451, net45, net451, net452, net46, net461, netcoreapp1.0, netstandard1.6
2016-09-12 20:03:18 -05:00
|
|
|
} 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)]
|
2016-12-08 19:23:52 -06:00
|
|
|
public static void Test()
|
2015-10-16 16:07:20 -05:00
|
|
|
{
|
2016-12-08 19:23:52 -06:00
|
|
|
System.Console.WriteLine($"{x++} Cron Job: Hello, world!");
|
code cleanup, migrated to dotnet core, builds for dnx46, dnx451, net45, net451, net452, net46, net461, netcoreapp1.0, netstandard1.6
2016-09-12 20:03:18 -05:00
|
|
|
//throw new ArgumentException("fail");
|
2015-10-16 16:07:20 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|