Skip to content

Commit dee9e61

Browse files
committed
fix issue 1->RecurreingJobAttribute timezoneInfo not supported
1 parent 66aeea8 commit dee9e61

File tree

10 files changed

+47
-28
lines changed

10 files changed

+47
-28
lines changed

Hangfire.RecurringJobExtensions.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{6E0E1A07-731
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7A9F6A71-9A61-4817-AE86-9254999FA206}"
99
ProjectSection(SolutionItems) = preProject
10+
appveyor.yml = appveyor.yml
1011
global.json = global.json
12+
README.md = README.md
1113
EndProjectSection
1214
EndProject
1315
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Hangfire.RecurringJobExtensions", "src\Hangfire.RecurringJobExtensions\Hangfire.RecurringJobExtensions.xproj", "{D75DFE5D-38CF-4150-8264-EB22E579237D}"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ JSON Token | Description
107107
**job-name** | *[required]* The job name to `RecurringJob`.
108108
**job-type** | *[required]* The job type while impl the interface `IRecurringJob`.
109109
**cron-expression** | *[required]* Cron expressions.
110-
timezone | *[optional]* Default value is `TimeZoneInfo.Local`.
110+
timezone | *[optional]* Default value is `TimeZoneInfo.Utc`.
111111
queue | *[optional]* The specified queue name , default value is `default`.
112112
job-data | *[optional]* Similar to the [quartz.net](http://www.quartz-scheduler.net/) `JobDataMap`, it is can be deserialized to the type `Dictionary<string,object>`.
113113
enable | *[optional]* Whether the `RecurringJob` can be added/updated, default value is true, if false `RecurringJob` will be deleted automatically.

samples/Hangfire.Samples/MyJob2.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public void Execute(PerformContext context)
2727
var simpleObject = context.GetJobData<SimpleObject>("SimpleObject");
2828

2929
context.WriteLine($"IntVal:{intVal},StringVal:{stringVal},BooleanVal:{booleanVal},simpleObject:{JobHelper.ToJson(simpleObject)}");
30+
31+
context.SetJobData("IntVal", ++intVal);
32+
33+
context.WriteLine($"IntVal changed to {intVal}");
3034
}
3135
}
3236
}

samples/Hangfire.Samples/RecurringJobService.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,30 @@ namespace Hangfire.Samples
77
{
88
public class RecurringJobService
99
{
10-
[RecurringJob("*/1 * * * *", RecurringJobId = "InstanceTestJob")]
11-
//[DisplayName("JobStaticTest")]
10+
[RecurringJob("*/1 * * * *")]
1211
[Queue("jobs")]
12+
public void TestJob1(PerformContext context)
13+
{
14+
context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} TestJob1 Running ...");
15+
}
16+
[RecurringJob("*/2 * * * *", RecurringJobId = "TestJob2")]
17+
[Queue("jobs")]
18+
public void TestJob2(PerformContext context)
19+
{
20+
context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} TestJob2 Running ...");
21+
}
22+
[RecurringJob("*/2 * * * *", "China Standard Time", "jobs")]
23+
public void TestJob3(PerformContext context)
24+
{
25+
context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} TestJob3 Running ...");
26+
}
27+
[RecurringJob("*/5 * * * *", "jobs")]
1328
public void InstanceTestJob(PerformContext context)
1429
{
1530
context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} InstanceTestJob Running ...");
1631
}
1732

18-
[RecurringJob("*/5 * * * *")]
19-
//[DisplayName("JobStaticTest")]
20-
[Queue("jobs")]
33+
[RecurringJob("*/6 * * * *", "UTC", "jobs")]
2134
public static void StaticTestJob(PerformContext context)
2235
{
2336
context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} StaticTestJob Running ...");

samples/Hangfire.Samples/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"Hangfire.RecurringJobExtensions": "1.1.3-*",
3+
"Hangfire.RecurringJobExtensions": "1.1.4-*",
44
"Hangfire.Console": "1.1.5",
55
"Hangfire.AspNetCore": "1.6.7",
66
"Hangfire.Core": "1.6.7",

src/Hangfire.RecurringJobExtensions/Configuration/JsonConfigurationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private RecurringJobInfo Convert(RecurringJobJsonOptions option)
5151
#endif
5252
Cron = option.Cron,
5353
Queue = option.Queue ?? EnqueuedState.DefaultQueue,
54-
TimeZone = option.TimeZone ?? TimeZoneInfo.Local,
54+
TimeZone = option.TimeZone ?? TimeZoneInfo.Utc,
5555
ExtendedData = option.ExtendedData,
5656
Enable = option.Enable ?? true
5757
};

src/Hangfire.RecurringJobExtensions/PerformContextExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using Hangfire.Common;
54
using Hangfire.Server;
65

src/Hangfire.RecurringJobExtensions/RecurringJobAttribute.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ namespace Hangfire.RecurringJobExtensions
1111
public class RecurringJobAttribute : Attribute
1212
{
1313
/// <summary>
14-
/// Cron expressions
14+
/// The identifier of the RecurringJob
1515
/// </summary>
16-
public string Cron { get; private set; }
16+
public string RecurringJobId { get; set; }
1717
/// <summary>
18-
/// TimeZoneInfo
18+
/// Cron expressions
1919
/// </summary>
20-
public TimeZoneInfo TimeZone { get; private set; }
20+
public string Cron { get; set; }
2121
/// <summary>
2222
/// Queue name
2323
/// </summary>
24-
public string Queue { get; private set; }
24+
public string Queue { get; set; }
2525
/// <summary>
26-
/// The identifier of the RecurringJob
26+
/// Converts to <see cref="TimeZoneInfo"/> via method <seealso cref="TimeZoneInfo.FindSystemTimeZoneById(string)"/>,
27+
/// default value is <see cref="TimeZoneInfo.Utc"/>
2728
/// </summary>
28-
public string RecurringJobId { get; set; }
29+
public string TimeZone { get; set; }
2930
/// <summary>
3031
/// Whether to build RecurringJob automatically, default value is true.
3132
/// If false it will be deleted automatically.
@@ -35,26 +36,20 @@ public class RecurringJobAttribute : Attribute
3536
/// Initializes a new instance of the <see cref="RecurringJobAttribute"/>
3637
/// </summary>
3738
/// <param name="cron">Cron expressions</param>
38-
public RecurringJobAttribute(string cron) : this(cron, TimeZoneInfo.Local) { }
39+
public RecurringJobAttribute(string cron) : this(cron, EnqueuedState.DefaultQueue) { }
3940
/// <summary>
4041
/// Initializes a new instance of the <see cref="RecurringJobAttribute"/>
4142
/// </summary>
4243
/// <param name="cron">Cron expressions</param>
4344
/// <param name="queue">Queue name</param>
44-
public RecurringJobAttribute(string cron, string queue) : this(cron, TimeZoneInfo.Local, queue) { }
45-
/// <summary>
46-
/// Initializes a new instance of the <see cref="RecurringJobAttribute"/>
47-
/// </summary>
48-
/// <param name="cron">Cron expressions</param>
49-
/// <param name="timeZone"><see cref="TimeZoneInfo"/></param>
50-
public RecurringJobAttribute(string cron, TimeZoneInfo timeZone) : this(cron, timeZone, EnqueuedState.DefaultQueue) { }
45+
public RecurringJobAttribute(string cron, string queue) : this(cron, "UTC", queue) { }
5146
/// <summary>
5247
/// Initializes a new instance of the <see cref="RecurringJobAttribute"/>
5348
/// </summary>
5449
/// <param name="cron">Cron expressions</param>
55-
/// <param name="timeZone"><see cref="TimeZoneInfo"/></param>
50+
/// <param name="timeZone">Converts to <see cref="TimeZoneInfo"/> via method <seealso cref="TimeZoneInfo.FindSystemTimeZoneById(string)"/>.</param>
5651
/// <param name="queue">Queue name</param>
57-
public RecurringJobAttribute(string cron, TimeZoneInfo timeZone, string queue)
52+
public RecurringJobAttribute(string cron, string timeZone, string queue)
5853
{
5954
Cron = cron;
6055
TimeZone = timeZone;

src/Hangfire.RecurringJobExtensions/RecurringJobBuilder.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4+
using Hangfire.States;
45

56
namespace Hangfire.RecurringJobExtensions
67
{
@@ -48,7 +49,12 @@ public void Build(Func<IEnumerable<Type>> typesProvider)
4849
RecurringJob.RemoveIfExists(attribute.RecurringJobId);
4950
continue;
5051
}
51-
_registry.Register(attribute.RecurringJobId, method, attribute.Cron, attribute.TimeZone, attribute.Queue);
52+
_registry.Register(
53+
attribute.RecurringJobId,
54+
method,
55+
attribute.Cron,
56+
string.IsNullOrEmpty(attribute.TimeZone) ? TimeZoneInfo.Utc : TimeZoneInfo.FindSystemTimeZoneById(attribute.TimeZone),
57+
attribute.Queue ?? EnqueuedState.DefaultQueue);
5258
}
5359
}
5460
}

src/Hangfire.RecurringJobExtensions/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.1.3-*",
2+
"version": "1.1.4-*",
33
"title": "Hangfire.RecurringJobExtensions",
44
"description": "Hangfire extensions for RecurringJob",
55
"authors": [ "icsharp" ],

0 commit comments

Comments
 (0)