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
10 changes: 10 additions & 0 deletions Hangfire.RecurringJobExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hangfire.Samples", "samples
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hangfire.RecurringJobExtensions.Tests", "test\Hangfire.RecurringJobExtensions.Tests\Hangfire.RecurringJobExtensions.Tests.csproj", "{B1AA8C91-161A-4A92-9B0A-B47742CDDB38}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hangfire.WebApi", "Hangfire.WebApi\Hangfire.WebApi.csproj", "{8D5930B9-B337-4722-86C0-F9229AC2960F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{B1AA8C91-161A-4A92-9B0A-B47742CDDB38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1AA8C91-161A-4A92-9B0A-B47742CDDB38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1AA8C91-161A-4A92-9B0A-B47742CDDB38}.Release|Any CPU.Build.0 = Release|Any CPU
{8D5930B9-B337-4722-86C0-F9229AC2960F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D5930B9-B337-4722-86C0-F9229AC2960F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D5930B9-B337-4722-86C0-F9229AC2960F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D5930B9-B337-4722-86C0-F9229AC2960F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -47,5 +53,9 @@ Global
{D75DFE5D-38CF-4150-8264-EB22E579237D} = {6E0E1A07-7311-4F8C-B1BD-B3803B6E621E}
{9DCBF5BA-414C-4E39-B264-CFD6C824AA66} = {B04B5FCE-89A8-4A3E-9671-CB3070C89AAF}
{B1AA8C91-161A-4A92-9B0A-B47742CDDB38} = {F5091E02-C3A4-407E-995C-86E07A801832}
{8D5930B9-B337-4722-86C0-F9229AC2960F} = {B04B5FCE-89A8-4A3E-9671-CB3070C89AAF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C54AE9A2-40D8-41BF-8974-E0F16F4AB0C2}
EndGlobalSection
EndGlobal
74 changes: 74 additions & 0 deletions Hangfire.WebApi/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Hangfire.RecurringJobExtensions.Manager;
using Hangfire.WebApi.TestJob;
using Microsoft.AspNetCore.Mvc;

namespace Hangfire.WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private readonly IScheduleJobManager ScheduleJobManager;

public ValuesController(IScheduleJobManager ScheduleJobManager)
{
this.ScheduleJobManager = ScheduleJobManager;
}

[HttpPost("Schedule")]
public async void Schedule([FromBody] object request)
{
var args1 = new SimpleJobArgs1()
{
//Name = request.Name,
//Data = new SimpleJobArgsData1 { MerNo = request.Data.MerNo, OrderNo = request.Data.OrderNo }
};

var args2 = new SimpleJobArgs2()
{
//Name = request.Name,
//Data = new SimpleJobArgsData2 { MerNo = request.Data.MerNo, OrderNo = request.Data.OrderNo }
};

await ScheduleJobManager.ExecuteScheduleAsync<SimpleJob, SimpleJobArgs1>(args1);
await ScheduleJobManager.ExecuteBackgroundJobAsync<SimpleJob2, SimpleJobArgs2>(null, TimeSpan.FromSeconds(55), args2);
//https://github.com/HangfireIO/Hangfire/issues/1168
}

// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}

// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}

// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}

// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}

// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
19 changes: 19 additions & 0 deletions Hangfire.WebApi/Hangfire.WebApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Hangfire.RecurringJobExtensions\Hangfire.RecurringJobExtensions.csproj" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions Hangfire.WebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Hangfire.WebApi
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
30 changes: 30 additions & 0 deletions Hangfire.WebApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:18803",
"sslPort": 44343
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Hangfire.WebApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
47 changes: 47 additions & 0 deletions Hangfire.WebApi/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Hangfire.WebApi
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseMvc();
}
}
}
36 changes: 36 additions & 0 deletions Hangfire.WebApi/TestJob/SimpleJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Hangfire.RecurringJobExtensions;
using Hangfire.RecurringJobExtensions.Manager;
using Hangfire.Server;
using Newtonsoft.Json;

namespace Hangfire.WebApi.TestJob
{
public class SimpleJob : IBackgroundJob
{
[RecurringJob("*/3 * * * *")]//At every 3th minute.
public Task Execute(PerformContext context)
{
var ctx = context as PerformContext;
var data = ctx.GetJobData();

Debug.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {JsonConvert.SerializeObject(data)} Running ...");
return Task.CompletedTask;
}
}

public class SimpleJobArgs1 : IJobData
{
public string Name { get; set; }
public SimpleJobArgsData1 Data { get; set; }
public string OrderNo { get; set; }
}

public class SimpleJobArgsData1
{
public string OrderNo { get; set; }
public string MerNo { get; set; }
}
}
32 changes: 32 additions & 0 deletions Hangfire.WebApi/TestJob/SimpleJob2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Hangfire.RecurringJobExtensions.Manager;
using Hangfire.Server;

namespace Hangfire.WebApi.TestJob
{
public class SimpleJob2 : IBackgroundJob<SimpleJobArgs2>
{
public Task Execute(PerformContext context, params SimpleJobArgs2[] args)
{
var ctx = context as PerformContext;

Debug.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {args[0].Name}'s SimpleJobArgs2 (ExecuteBackgroundJobAsync) is Running ...");
return Task.CompletedTask;
}
}

public class SimpleJobArgs2 : IJobData
{
public string Name { get; set; }
public SimpleJobArgsData2 Data { get; set; }
public string OrderNo { get; set; }
}

public class SimpleJobArgsData2
{
public string OrderNo { get; set; }
public string MerNo { get; set; }
}
}
9 changes: 9 additions & 0 deletions Hangfire.WebApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
8 changes: 8 additions & 0 deletions Hangfire.WebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Hangfire.RecurringJobExtensions Fork Version
--With encapsulation of the the interface ScheduleJobManager, which support DI. Like following:
```csharp
await ScheduleJobManager.ExecuteScheduleAsync<SimpleJob, SimpleJobArgs1>(args1);
await ScheduleJobManager.ExecuteBackgroundJobAsync<SimpleJob2, SimpleJobArgs2>(null, TimeSpan.FromSeconds(55), args2);
```
# Hangfire.RecurringJobExtensions

[![Official Site](https://img.shields.io/badge/site-hangfire.io-blue.svg)](http://hangfire.io)
Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ test_script:
- cmd: >-
cd test\Hangfire.RecurringJobExtensions.Tests

dotnet test
dotnet test
image: Visual Studio 2017
15 changes: 7 additions & 8 deletions samples/Hangfire.Samples/Hangfire.Samples.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>Hangfire.Samples</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Hangfire.Samples</PackageId>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,10 +15,6 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Hangfire.RecurringJobExtensions\Hangfire.RecurringJobExtensions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hangfire.Console" Version="1.1.5" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.6.7" />
Expand All @@ -32,4 +27,8 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Hangfire.RecurringJobExtensions\Hangfire.RecurringJobExtensions.csproj" />
</ItemGroup>

</Project>
Loading