Sisyphus
Keeps rolling that rock uphill on schedule.
TOC
- Getting Started
- External Dependencies
- Creating a New Job Project
- Implementing a Job
- Registering a Job in Sisyphus.Service
Getting Started
- Clone the repository:
git clone https://github.com/NotMyself/Sisyphus.git
. - Change directory into the cloned repository
cd Sisyphus
. - Run script to register uri:
script/register_uri.ps1
. - Open the
Sisyphus.sln
in Visual Studio. - Open the Sql Server Object Explorer View, View > Sql Server Object Explorer.
- Under the
(localdb)\MSSQLLocalDB
node, right click Databases and selectAdd New Database
. - Set Database Name to
Sisyphus
and clickOK
. - Hit
F5
to start the service as a console application. - You should now be able to browse to http://localhost:8080 to see the Hangfire Dashboard.
External Dependencies
- Autofac - Dependency Intection framework used for service and plugin registration
- TopShelf - Service host framework used to host in console or windows service
- Hangfire - Background Job Processing framework used to schedule and execute long running jobs
- Hangfire.Pro - Extensions to Hangfire that add several advanced job type scenarios
Creating a New Job Project
-
Open the
Sisyphus.sln
solution. -
Right click on the
Jobs
solution folder and select Add > New Project -
Select
Class Library
from theVisual C#
section. -
Name your library
Sisyphus.Jobs.*JobName*
where JobName is the name of a single job or collection of jobs. -
Set the Location to the
src
folder located at the root of the repository. -
Right click your new project and select Add > Existing Item.
-
Navigate to the
src
folder and select theSolutionInfo.cs
file. -
From the
Add
button drop down menu, selectAdd As Link
. -
Drag the linked
SolutionInfo.cs
into theProperties
folder. -
Open the
AssemblyInfo.cs
file in the Properties folder and remove all attrubutes except these:- AssemblyTitle
- AssemblyDescription
- Guid
-
Right click the Solution and select Manage Nuget Packages for Solution.
-
You may be prompted for credentails for the Hanfire nuget feed, they can be found in NuGet.config.
-
Add NuGet references to the following pacakges to your project using the installed tab of the Nuget Manager:
- Autofac
- Hangfire.Pro
- Hangfire.Autofac
-
Right click the new project and select Properties.
-
Select the Build tab and modify the Output Directory for both Debug and Release as follows:
- Debug = ..\Sisyphus.Service\bin\Debug\
- Release = ..\Sisyphus.Service\bin\Release\
-
Right click the Solution and select
Project Dependecies
. -
For the project
Sisyphus.Service
add a check next to your new project. -
Build the Solution.
-
Ensure your new project's built assembly is located in the
bin
directory for the Sisyphus.Service project.
Implementing a Job
- Your new job project should have a Class1.cs, open it.
- Implement the following interfaces found in
Sisyphus.Core
:- IBackgroundJob - implements the asyncronous
Task
to be run - IBackgroundJobSchedule - implements the schedule to run the Task
- IBackgroundJobScheduler - implements the scheduling action
- IBackgroundJob - implements the asyncronous
- Rename the
Class1
class to something appropreate for your job as well as theClass1.cs
file.
Registering a Job in Sisyphus.Service
-
Add a new class named
*JobName*Module
where JobName is the name of your job or the collection of jobs.- It should match the name of your project.
-
Inherit from the
Module
base class inAutofac
. -
Override the
Load
method from theModule
base class. -
Using the
ContainerBuilder
register each of your jobs asself
,IBackgroundJob
andIBackgroundJobScheduler
builder.RegisterType<ExampleJob>() .AsSelf() .As<IBackgroundJob>() .As<IBackgroundJobScheduler>();
-
In the Sisyphus.Service project, open the App.config.
-
In the
autofac\modules
section add a weak assembly reference to your module.<module type="Sisyphus.Jobs.Example.ExampleModule, Sisyphus.Jobs.Example" />
-
Build the Solution and Run.
-
You should now see your job listed on the Hangfire Dashboard.