-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
3,259 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Jobs | ||
|
||
A job is basically a task that you either don't want to execute in the current | ||
context, on the current server or execute at a later time. EventFlow provides | ||
basic functionality for jobs. | ||
|
||
There are areas where you might find jobs very useful, here are some examples | ||
|
||
* Publish a command at a specific time in the future | ||
* Transient error handling | ||
|
||
```csharp | ||
var jobScheduler = resolver.Resolve<IJobScheduler>(); | ||
var job = PublishCommandJob.Create(new SendEmailCommand(id), resolver); | ||
await jobScheduler.ScheduleAsync( | ||
job, | ||
TimeSpan.FromDays(7), | ||
CancellationToken.None) | ||
.ConfigureAwait(false); | ||
``` | ||
|
||
In the above example the `SendEmailCommand` command will be published in seven | ||
days. | ||
|
||
## Be careful when using jobs | ||
|
||
When working with jobs, you should be aware of the following | ||
|
||
* The default implementation does executes the job _now_, i.e., in the | ||
current context. To get another behavior, install e.g. `EventFlow.Hangfire` | ||
to get support for scheduled jobs. Read below for details on how to | ||
configure Hangfire | ||
* Your jobs should serialize to JSON properly, see the section on | ||
[value objects](./ValueObjects.md) for more information | ||
* If you use the provided `PublishCommandJob`, make sure that your commands | ||
serialize properly as well | ||
|
||
## Create your own jobs | ||
|
||
To create your own jobs, your job merely needs to implement the `IJob` | ||
interface and be registered in EventFlow. | ||
|
||
Here's an example of a job implementing `IJob` | ||
|
||
```csharp | ||
[JobVersion("LogMessage", 1)] | ||
public class LogMessageJob : IJob | ||
{ | ||
public LogMessageJob(string message) | ||
{ | ||
Message = message; | ||
} | ||
|
||
public string Message { get; } | ||
|
||
public Task ExecuteAsync( | ||
IResolver resolver, | ||
CancellationToken cancellationToken) | ||
{ | ||
var log = resolver.Resolve<ILog>(); | ||
log.Debug(Message); | ||
} | ||
} | ||
``` | ||
|
||
Note that the `JobVersion` attribute specifies the job name and version to | ||
EventFlow and this is how EventFlow distinguishes between the different job | ||
types. This makes it possible for you to reorder your code, even rename the | ||
job type, as long as you keep the same attribute values its considered the | ||
same job in EventFlow. If the attribute is omitted, the name will be the | ||
type name and version will be `1`. | ||
|
||
Here's how the job is registered in EventFlow. | ||
|
||
```csharp | ||
var resolver = EventFlowOptions.new | ||
.AddJobs(typeof(LogMessageJob)) | ||
... | ||
.CreateResolver(); | ||
``` | ||
|
||
Then to schedule the job | ||
|
||
```csharp | ||
var jobScheduler = resolver.Resolve<IJobScheduler>(); | ||
var job = new LogMessageJob("Great log message"); | ||
await jobScheduler.ScheduleAsync( | ||
job, | ||
TimeSpan.FromDays(7), | ||
CancellationToken.None) | ||
.ConfigureAwait(false); | ||
``` | ||
|
||
## Hangfire | ||
|
||
To use [Hangfire](http://hangfire.io/) as the job scheduler, install the NuGet | ||
package `EventFlow.Hangfire` and configure EventFlow to use the scheduler | ||
like this. | ||
|
||
```csharp | ||
var resolver = EventFlowOptions.new | ||
.UseHandfireJobScheduler() // This line | ||
... | ||
.CreateResolver(); | ||
``` | ||
|
||
Note that the `UseHandfireJobScheduler()` does do any Hangfire configuration, | ||
but merely registers the proper scheduler in EventFlow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Source/EventFlow.Hangfire.Tests/EventFlow.Hangfire.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{35180FC7-9135-4E79-8643-0FB825B40871}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>EventFlow.Hangfire.Tests</RootNamespace> | ||
<AssemblyName>EventFlow.Hangfire.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="FluentAssertions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\FluentAssertions.4.0.0\lib\net45\FluentAssertions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="FluentAssertions.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\FluentAssertions.4.0.0\lib\net45\FluentAssertions.Core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Hangfire.Core, Version=1.4.6.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Hangfire.Core.1.4.6\lib\net45\Hangfire.Core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Hangfire.SqlServer, Version=1.4.6.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Hangfire.SqlServer.1.4.6\lib\net45\Hangfire.SqlServer.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Helpz, Version=0.1.8.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Helpz.0.1.8\lib\net451\Helpz.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Integration\HangfireJobFlow.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\EventFlow.Hangfire\EventFlow.Hangfire.csproj"> | ||
<Project>{fb079985-722a-43c9-9f14-c7d2afbe8826}</Project> | ||
<Name>EventFlow.Hangfire</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj"> | ||
<Project>{571d291c-5e4c-43af-855f-7c4e2f318f4c}</Project> | ||
<Name>EventFlow.TestHelpers</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\EventFlow\EventFlow.csproj"> | ||
<Project>{11131251-778d-4d2e-bdd1-4844a789bca9}</Project> | ||
<Name>EventFlow</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Oops, something went wrong.