hangfire

Set an “on demand” only job in HangFire

女生的网名这么多〃 提交于 2019-12-06 19:19:34
问题 In Hangfire, I have successfully set recurring jobs and am able to trigger manually if I want to, thanks to the Web UI and its "trigger" button. RecurringJob.AddOrUpdate(..); But I'm willing to set a job that is never fired automatically. Only on demand from the WebUi. Think of it as a set of maintenance task that are triggered only when needed. Manually. I was thinking of adding a non-reccuring Job in the await state, but was not able to (and it sounds wrong). Are "On demand only" jobs

Net定时器 【转载】

你说的曾经没有我的故事 提交于 2019-12-06 16:14:45
【转载】 Timer Timer是.NET内置的定时器类,它位于命名空间 System.Timers 下。Timer是一个基于服务器端的计时器,提供了 Interval 属性来设置重复触发定时任务的间隔(单位为毫秒),触发事件则由 Elapsed 事件来指定。另外,还可以通过 AutoReset 属性来设置Timer的 Elapsed 事件只触发一次或者重复触发。 官方地址: https://docs.microsoft.com/en-us/dotnet/api/system.timers.timer?view=netframework-4.8 特性 轻量,简单易用 .NET框架内置,无须引用第三方库 不支持Cron表达式 FluentScheduler FluentScheduler是由一位巴西的.NET开发者 Talles L 开发并维护的.NET平台下的一款自动定时任务调度器组件,它提供了比较丰富的定时任务调度接口,开发者可以快速方便地通过接口设置调度时间,比如:间隔1秒,2秒…n秒,只执行一次,哪月的哪一天等等。具体请参考我之前写过的两篇关于FluentScheduler的文章: 《推荐一个简单、轻量、功能非常强大的C#/ASP.NET定时任务执行管理器组件—FluentScheduler》 《简单、轻量、功能非常强大的C#/ASP.NET定时调度任务执行管理组件

c# .net 4.5.2 asp.net mvc 使用hangfire

巧了我就是萌 提交于 2019-12-06 14:17:51
一定要有hangfire数据库,否则hangfire会报错。 1.准备个空库给hangfire使用。 2.添加OWIN Startup 类。在类库上-右键-添加-新建项-搜索startup 3. 在 app.UseHangfireServer(); 下一行创建任务计划 web.config: <connectionStrings> <add name="HangfireDb_connection" connectionString="Data Source=.;Initial Catalog=HangfireDb;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> - Startup1.cs using System; using System.Threading.Tasks; using Microsoft.Owin; using Owin; using Hangfire; [assembly: OwinStartup(typeof(任务计划HangFire.Startup1))] namespace 任务计划HangFire { public class Startup1 { public void Configuration(IAppBuilder app

Using Postal and Hangfire in Subsite

扶醉桌前 提交于 2019-12-06 10:49:57
I have been trying to use Postal on my MVC5 site. When I host my webpage a subsite ie, http://localhost/Subsite I am receiving the error The virtual path '/' maps to another application, which is not allowed I have debugged it down to when the ControllerContext is being created the HttpContext isn't getting set correctly. Since I'm running Postal from Hangfire the HttpContext.Current is always null. Postal creates the ContollerContext using the code below. ControllerContext CreateControllerContext() { // A dummy HttpContextBase that is enough to allow the view to be rendered. var httpContext =

Object getting Null seems like deserialization issue in Hangfire

ぐ巨炮叔叔 提交于 2019-12-06 09:01:47
It seems like Hangfire is unable to deserialize my original Scheduler object with all its state, whose Execute method I am calling in BackgroundJob.Enqueue() as shown below: Scheduler = new FileInFileOut { FileIn = new FileInput() { FileName = "SampleInput.txt", DirectoryPath = @"C:\Users\LENOVO\Desktop\iRule", FileFormat = new System.Collections.Generic.Dictionary<string, string> { {"X", "ParseInt(input.Substring(0, 2))"}, {"Y", "ParseInt(input.Substring(3, 2))"}, {"Z", "ParseInt(input.Substring(6, 2))"}, } }, FileOut = new FileOutput() { FileName = "SampleOutput.txt", DirectoryPath = @"C:

MVC中使用Hangfire按秒执行任务

冷暖自知 提交于 2019-12-05 19:08:15
1、更新Hangfire版本到1.7.0,才支持使用按秒循环任务执行RecurringJob.AddOrUpdate("test",()=>writeLog("每20秒执行任务"), "*/20 * * * * *");2、修改参数 var jobOptions = new BackgroundJobServerOptions { Queues = new[] { "critical", "test", "default" }, WorkerCount = Environment.ProcessorCount * int.Parse(Configuration["Hangfire:ProcessorCount"]), ServerName = Configuration["Hangfire:ServerName"], SchedulePollingInterval = TimeSpan.FromSeconds(1), //计划轮询间隔 支持任务到秒 }; 来源: https://www.cnblogs.com/lyl6796910/p/11940201.html

Keep history of jobs executed for more than 1 day in Hangfire

拟墨画扇 提交于 2019-12-05 14:44:17
I've just started using Hangfire, and I am loving it. I understand that Hangfire maintains the history for succeeded jobs for 1 day, and clear it thereafter. Is there is a way where I can customize this default behavior and persist the history for any duration say 7 days? To do this, you need to create a job filter and register it through hangfire global configurations, as discussed here - https://discuss.hangfire.io/t/how-to-configure-the-retention-time-of-job/34 Create job filter - using Hangfire.Common; using Hangfire.States; using Hangfire.Storage; using System; namespace HangfireDemo {

Is there an in memory job storage package for Hangfire?

拜拜、爱过 提交于 2019-12-05 12:27:19
问题 I have a console application to test HangFire. Here is the code: using System; using Hangfire; namespace MyScheduler.ConsoleApp { internal static class Program { internal static void Main(string[] args) { MyMethod(); Console.WriteLine("[Finished]"); Console.ReadKey(); } private static void MyMethod() { RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Minutely); } } } But it throws an exception on runtime: Additional information: JobStorage.Current property value has not been

How to invoke async methods in Hangfire?

╄→гoц情女王★ 提交于 2019-12-05 11:59:36
问题 I have asp.net core API application and this is the first time i will be using HangFire. In .Net Core application all my methods are async. Based on SO Post it's not good idea to use wait() while calling async method in hangfire. Also as per the hangfire support issue in v1.6.0, async support was added. I am using version 1.6.12 but still i dont see async support. How do i call async method from Enqueue . Currently i am using wait() public class MyController : Controller { private readonly

How do I get the current attempt number on a background job in Hangfire?

让人想犯罪 __ 提交于 2019-12-05 08:15:10
There are some database operations I need to execute before the end of the final attempt of my Hangfire background job (I need to delete the database record related to the job) My current job is set with the following attribute: [AutomaticRetry(Attempts = 5, OnAttemptsExceeded = AttemptsExceededAction.Delete)] With that in mind, I need to determine what the current attempt number is, but am struggling to find any documentation in that regard from a Google search or Hangfire.io documentation. Simply add PerformContext to your job method; you'll also be able to access your JobId from this object