Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Hangfire.Raven.Samples.Embedded/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
10 changes: 10 additions & 0 deletions Hangfire.Raven.Samples.Embedded/GenericServices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Hangfire.Raven.Samples.Embedded
{
public class GenericServices<TType>
{
public void Method<TMethod>(TType arg1, TMethod arg2)
{
System.Console.WriteLine("Arg1: {0}, Arg2: {1}", arg1, arg2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{7CFDAF39-D58A-4AB7-BF7A-931B858B7A53}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Hangfire.Raven.Samples.Embedded</RootNamespace>
<AssemblyName>Hangfire.Raven.Samples.Embedded</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Hangfire.Core, Version=1.6.17.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hangfire.Core.1.6.17\lib\net45\Hangfire.Core.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</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>
</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="GenericServices.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Hangfire.Raven\Hangfire.Raven.csproj">
<Project>{ba18f6bf-5613-4b9d-a57a-c05c51148ec5}</Project>
<Name>Hangfire.Raven</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
58 changes: 58 additions & 0 deletions Hangfire.Raven.Samples.Embedded/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using Hangfire.Raven.Storage;

namespace Hangfire.Raven.Samples.Embedded
{
public static class Program
{
public static int x = 0;

public static void Main()
{
try {
// you can use Raven Storage and specify the connection string name
//GlobalConfiguration.Configuration
// .UseColouredConsoleLogProvider()
// .UseRavenStorage("RavenDebug");

// you can use Raven Storage and specify the connection string and database name
//GlobalConfiguration.Configuration
// .UseColouredConsoleLogProvider()
// .UseRavenStorage("http://localhost:9090", "HangfireConsole");

// you can use Raven Embedded Storage which runs in memory!
GlobalConfiguration.Configuration
.UseColouredConsoleLogProvider()
.UseEmbeddedRavenStorage();

//you have to create an instance of background job server at least once for background jobs to run
var client = new BackgroundJobServer();

// Run once delayed
BackgroundJob.Schedule(() => Console.WriteLine("Delayed Background job: Hello, world!"), TimeSpan.FromSeconds(20));

//Run once immediately
BackgroundJob.Enqueue(() => Console.WriteLine("Background Job: Hello, world!"));
BackgroundJob.Enqueue(() => Console.WriteLine("Background Job: Hello, world again!"));
BackgroundJob.Enqueue(() => Console.WriteLine("Background Job: Hello, world a third time!"));

BackgroundJob.Enqueue(() => Test());

// Run every minute
RecurringJob.AddOrUpdate(() => Test(), Cron.Minutely);

System.Console.WriteLine("Press Enter to exit...");
System.Console.ReadLine();
} catch (Exception ex) {
throw ex;
}
}

[AutomaticRetry(Attempts = 2, LogEvents = true, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public static void Test()
{
System.Console.WriteLine($"{x++} Cron Job: Hello, world!");
//throw new ArgumentException("fail");
}
}
}
36 changes: 36 additions & 0 deletions Hangfire.Raven.Samples.Embedded/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Hangfire.Raven.Samples.Embedded")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Hangfire.Raven.Samples.Embedded")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7cfdaf39-d58a-4ab7-bf7a-931b858b7a53")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
107 changes: 107 additions & 0 deletions Hangfire.Raven.Samples.Embedded/Services.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;

namespace Hangfire.Raven.Samples.Embedded
{
public class Services
{
private static readonly Random _random = new Random();

public void EmptyDefault()
{
}

[Queue("critical")]
public void EmptyCritical()
{
}

[AutomaticRetry(Attempts = 0)]
public void Error()
{
System.Console.WriteLine("Beginning error task...");
throw new InvalidOperationException(null, new FileLoadException());
}

[Queue("critical")]
public void Random(int number)
{
int time;
lock (_random)
{
time = _random.Next(10);
}

if (time < 5)
{
throw new Exception();
}

Thread.Sleep(TimeSpan.FromSeconds(5 + time));
System.Console.WriteLine("Finished task: " + number);
}

public void Cancelable(int iterationCount, IJobCancellationToken token)
{
try
{
for (var i = 1; i <= iterationCount; i++)
{
Thread.Sleep(1000);
System.Console.WriteLine("Performing step {0} of {1}...", i, iterationCount);

token.ThrowIfCancellationRequested();
}
}
catch (OperationCanceledException)
{
System.Console.WriteLine("Cancellation requested, exiting...");
throw;
}
}

public void Args(string name, int authorId, DateTime createdAt)
{
System.Console.WriteLine("{0}, {1}, {2}", name, authorId, createdAt);
}

public void Custom(int id, string[] values, CustomObject objects, DayOfWeek dayOfWeek)
{
}

public void FullArgs(
bool b,
int i,
char c,
DayOfWeek e,
string s,
TimeSpan t,
DateTime d,
CustomObject o,
string[] sa,
int[] ia,
long[] ea,
object[] na,
List<string> sl)
{
}

public class CustomObject
{
public int Id { get; set; }
public CustomObject[] Children { get; set; }
}

public void Write(char character)
{
System.Console.Write(character);
}

public void WriteBlankLine()
{
System.Console.WriteLine();
}
}
}
6 changes: 6 additions & 0 deletions Hangfire.Raven.Samples.Embedded/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Hangfire.Core" version="1.6.17" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
<package id="Owin" version="1.0" targetFramework="net461" />
</packages>
9 changes: 8 additions & 1 deletion Hangfire.Raven.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
VisualStudioVersion = 15.0.27004.2008
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{8CF2D2F6-BEFE-47FE-B141-0017FC6F97D8}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hangfire.Raven.Samples.AspN
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hangfire.Raven.Samples.Console", "samples\Hangfire.Raven.Samples.Console\Hangfire.Raven.Samples.Console.csproj", "{A7691484-4466-4F8C-9B57-C77EA0FF4670}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hangfire.Raven.Samples.Embedded", "Hangfire.Raven.Samples.Embedded\Hangfire.Raven.Samples.Embedded.csproj", "{7CFDAF39-D58A-4AB7-BF7A-931B858B7A53}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,6 +43,10 @@ Global
{A7691484-4466-4F8C-9B57-C77EA0FF4670}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7691484-4466-4F8C-9B57-C77EA0FF4670}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7691484-4466-4F8C-9B57-C77EA0FF4670}.Release|Any CPU.Build.0 = Release|Any CPU
{7CFDAF39-D58A-4AB7-BF7A-931B858B7A53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CFDAF39-D58A-4AB7-BF7A-931B858B7A53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CFDAF39-D58A-4AB7-BF7A-931B858B7A53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CFDAF39-D58A-4AB7-BF7A-931B858B7A53}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -49,6 +55,7 @@ Global
{BA18F6BF-5613-4B9D-A57A-C05C51148EC5} = {EF9BFE2C-0386-4EC4-83EC-D7E315F56735}
{34B7ED1A-796C-40B8-A8B9-D12D88C8A880} = {F42EDD6E-883B-4067-94AD-72EC7A095BF2}
{A7691484-4466-4F8C-9B57-C77EA0FF4670} = {F42EDD6E-883B-4067-94AD-72EC7A095BF2}
{7CFDAF39-D58A-4AB7-BF7A-931B858B7A53} = {F42EDD6E-883B-4067-94AD-72EC7A095BF2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1E710484-845C-4FAB-9F3F-2E3384385445}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.6.17" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions samples/Hangfire.Raven.Samples.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public static void Main()
// .UseColouredConsoleLogProvider()
// .UseRavenStorage("http://localhost:9090", "HangfireConsole");

// you can use Raven Embedded Storage which runs in memory!
//GlobalConfiguration.Configuration
// .UseColouredConsoleLogProvider()
// .UseEmbeddedRavenStorage();

//you have to create an instance of background job server at least once for background jobs to run
var client = new BackgroundJobServer();
Expand Down
Loading