This is a demo for using Hangfire server to run schedules jobs.
Now project is setup to consume HangfireWorkerService.Shared
and HangfireWorkerService.SampleJobs
as NuGet packages.
You will need a NuGet server to publish tha packages (in case you don't want to use NuGet - read this section).
This project uses Nuke build to assemble the project.
To push packages to your NuGet server you need to run
- on Windows:
PS> ./build.ps1 -target PushAllNugets -buildVersion "Your build version here" -NuGetServerUrl "Your NuGet server url" -NuGetApiKey "Your NuGet server API key"
- on Linux:
$> ./build.sh -target PushAllNugets -buildVersion "Your build version here" -NuGetServerUrl "Your NuGet server url" -NuGetApiKey "Your NuGet server API key"
- Remove
HangfireWorkerService.Shared
andHangfireWorkerService.SampleJobs
packages fromHangfireWorkerService
project. - Remove
HangfireWorkerService.Shared
fromHangfireWorkerService.SampleJobs
projects. - Add
HangfireWorkerService.Shared
toHangfireWorkerService.SampleJobs
project dependencies. - Add
HangfireWorkerService.Shared
andHangfireWorkerService.SampleJobs
projects toHangfireWorkerService
project dependencies.
Now you can restore packages and run a service from Visual Studio
Jobs are distributed in a NuGet packages. Jobs should implement IConfigurableJob
interface.
You can configure job peoperties to utilize different Hangfire job types.
JobType
determines how your job will be executed (i.e. one time or recurring)Interval
- interval for recurring jobs. Hangfire will start job again regardless if previous run finished or still in progress.Delay
- delay for schedule jobs.JobId
- string identifier for recurring jobs.SectionName
- appsettings.json file section with job config.