Skip to content

Commit 7c9beb4

Browse files
committed
- Updated to Cofoundry v0.10 pre-release
- Added some additional validation around recurring task intervals.
1 parent 68deb4f commit 7c9beb4

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

src/Cofoundry.Plugins.BackgroundTasks.Hangfire/Cofoundry.Plugins.BackgroundTasks.Hangfire.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Cofoundry.Web" Version="0.9.2" />
19-
<PackageReference Include="Hangfire" Version="1.7.24" />
18+
<PackageReference Include="Cofoundry.Web" Version="0.9.3-reworking-user-a0099" />
19+
<PackageReference Include="Hangfire" Version="1.7.28" />
2020
</ItemGroup>
2121
</Project>

src/Cofoundry.Plugins.BackgroundTasks.Hangfire/HangfireBackgroundTaskScheduler.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
using Hangfire;
1+
using Cofoundry.Core.BackgroundTasks;
2+
using Hangfire;
23
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using Cofoundry.Core.BackgroundTasks;
84

95
namespace Cofoundry.Plugins.BackgroundTasks.Hangfire
106
{
117
public class HangfireBackgroundTaskScheduler : IBackgroundTaskScheduler
128
{
13-
#region public methods
14-
159
public IBackgroundTaskScheduler RegisterRecurringTask<TTask>(int days, int atHour, int atMinute) where TTask : IRecurringBackgroundTask
1610
{
1711
ValidateDailyTaskParameters(days, atHour, atMinute);
@@ -110,10 +104,6 @@ public IBackgroundTaskScheduler DeregisterAsyncRecurringTask<TTask>() where TTas
110104
return this;
111105
}
112106

113-
#endregion
114-
115-
#region private methods
116-
117107
private string GetJobId<TTask>()
118108
{
119109
return typeof(TTask).FullName;
@@ -151,6 +141,15 @@ private void ValidateHourlyTaskParameters(int hours, int minute)
151141
throw new ArgumentOutOfRangeException(nameof(hours), "Recurring tasks need to have an interval of at least 1 minute.");
152142
}
153143

144+
if (hours > 23)
145+
{
146+
throw new ArgumentOutOfRangeException(nameof(hours), "Recurring tasks with an interval of 24 hours or more should be scheduled using a daily interval instead.");
147+
}
148+
149+
if (minute > 59)
150+
{
151+
throw new ArgumentOutOfRangeException(nameof(hours), "Recurring tasks with an interval measured in hours and minutes cannot have an minute component greater than 59 minutes.");
152+
}
154153
}
155154

156155
private void ValidateMinuteTaskParameters(int minutes)
@@ -169,7 +168,5 @@ private void ValidateNotNegative(int number, string argumentName)
169168
throw new ArgumentOutOfRangeException(argumentName, "Recurring tasks cannot set the interval to negative numbers.");
170169
}
171170
}
172-
173-
#endregion
174171
}
175172
}

src/HangfireSample/HangfireSample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Cofoundry.Web.Admin" Version="0.9.2" />
10+
<PackageReference Include="Cofoundry.Web.Admin" Version="0.9.3-reworking-user-a0099" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

0 commit comments

Comments
 (0)