Job Scheduler/Background processor for recurring jobs within a date range
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md Added notes to readme.md about new CI Nuget packages Nov 20, 2017

README.md

Hangfire.RecurringDateRange

Job Scheduler/Background processor for recurring jobs within a specified date range. Jobs are stored under a new recurring-daterange-job type, so they won't conflict with any jobs created with the existing recurring-job type.

Branch Build Status
Master Build status

Installation

Run the following from Package Manager Console:

  Install-Package Hangfire.RecurringDateRange

Also, during development/testing, I will frequently publish CI builds to Nuget as pre-release builds (so I can test/debug from my own projects that use Hangfire.RecurringDateRange.) If you want to use these un-tested builds at your own risk, run the following command:

  Install-Package -IncludePrerelease Hangfire.RecurringDateRange

Usage

To use, pass in a new instance of RecurringDateRangeJobScheduler() into UseHangfireServer:

  var backgroundServerJobOptions = new BackgroundJobServerOptions();
  appBuilder.UseHangfireServer(backgroundServerJobOptions, new RecurringDateRangeJobScheduler());

This library also uses NCrontab.Advanced for cron expression parsing. You can specify the format of your cron expressions via the cronStringFormat parameter:

  appBuilder.UseHangfireServer(backgroundServerJobOptions, new RecurringDateRangeJobScheduler(CronStringFormat.WithSecondsAndYears));

By default, RecurringDateRangeJobScheduler will use the time component of the start/end dates. If you want to ignore them, you can pass true/false as the 2nd parameter to the constructor (false is default):

  // Ingore the time component on start/end dates
  appBuilder.UseHangfireServer(backgroundServerJobOptions, new RecurringDateRangeJobScheduler(CronStringFormat.WithSecondsAndYears, true));

Then, instead of using the RecurringJob static methods, use the RecurringDateRangeJob static methods to create/remove jobs:

  // Runs a job every second between the 1st and 27th of January 2017
  RecurringDateRangeJob.AddOrUpdate("my-date-range-job",
      () => Console.WriteLine("Awesomesauce!"), "* * * * *",
      startDate: DateTime.Parse("2017-01-01"),
      endDate: DateTime.Parse("2017-01-27")
  );

  RecurringDateRangeJob.RemoveIfExists("my-date-range-job")