Search code examples
hangfire

One-off job with hangfire


How can I run a one-off job with hangfire?

It doesn't look that CRON syntax supports "run at startup and never again" type of thing.

I don't want to come up with a fixed CRON date (like 2019-02-28T15:12), because that wouldn't work across several environments.

Any ideas how to do it?


Solution

  • What we ended up with is a job that never runs, but can be triggered via Hangfire UI.

    So something like this:

    RecurringJob.AddOrUpdate<SomeType>("name", service => service.Run(), NEVER);
    

    For NEVER we use Hangfire's Cron.Never() implementation. It looks like it uses Each 31st of February for the cron expression. More info on their Github.