Note: version 1 is compatible with Umbraco 9 and version 2 is compatible with Umbraco 10 and up.
This installs Hangfire and a dashboard in Umbraco, the dashboard is secured and is only available for users with access to the Settings section of Umbraco.
As of v2.0.1, you can now use a separate database for Hangfire, the connection string name then should be: hangfireDB.
For more info:
After installing this package, you can start creating Jobs from a composer, for example:
using System.Threading;
using Hangfire;
using Hangfire.Console;
using Hangfire.Server;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
namespace MyNamespace
{
public class Composer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
RecurringJob.AddOrUpdate(() => DoIt(null), Cron.Hourly());
}
public void DoIt(PerformContext context)
{
var progressBar = context.WriteProgressBar();
var items = new int[10]{ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
foreach (var item in items.WithProgress(progressBar, items.Length))
{
context.WriteLine($"Number: {item}");
Thread.Sleep(1000);
}
}
}
}