Set an “on demand” only job in HangFire

前端 未结 4 849
粉色の甜心
粉色の甜心 2021-02-13 17:18

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.A         


        
4条回答
  •  甜味超标
    2021-02-13 17:41

    Manual or "on demand" have not yet been implemented in the main trunk. However you can use this fork to have that option.

    Currently this is marked as Work in Progress in Hangfire's repo and you can use it as this:

    BackgroundJob.Stash(() => Console.WriteLine("STASHING"));
    

    A different approach mentioned in one of the comments is to have somewhere in your site a button that enqueues the job:

    BackgroundJob.Enqueue(() => Console.WriteLine("Simple!"));
    

    EDIT: 2017/12/28:

    Apparently the previous fork wont be merged back since this extension already supports to manually queue jobs:

    Hangfire.Core.Dashboard.Management

提交回复
热议问题