Created
July 12, 2016 11:01
-
-
Save hikalkan/d543b6ded179d1f05227f49bc70e2fbe to your computer and use it in GitHub Desktop.
Example usage of HangFire's RecurringJob in ABP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Abp.Dependency; | |
using Castle.Core.Logging; | |
namespace Halil.HangfireTests.Web.Controllers | |
{ | |
public class MyJob1Class : ITransientDependency | |
{ | |
private readonly ILogger _logger; | |
public MyJob1Class(ILogger logger) | |
{ | |
_logger = logger; | |
} | |
public void DoIt() | |
{ | |
_logger.Info("MyJob1Class is working!"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
using Abp.Web.Mvc.Controllers; | |
using Hangfire; | |
namespace Halil.HangfireTests.Web.Controllers | |
{ | |
public class MyTestController : AbpController | |
{ | |
private readonly MyJob1Class _myJob1Class; | |
public MyTestController(MyJob1Class myJob1Class) | |
{ | |
_myJob1Class = myJob1Class; | |
} | |
public JsonResult Index() | |
{ | |
RecurringJob.RemoveIfExists("Job1"); | |
RecurringJob.AddOrUpdate( | |
"Job1", | |
() => _myJob1Class.DoIt(), | |
Cron.Daily(10, 59) | |
); | |
return Json("OK", JsonRequestBehavior.AllowGet); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment