Skip to content

Commit

Permalink
Merge pull request #66 from bamotav/new-issue
Browse files Browse the repository at this point in the history
Fix issue #60
  • Loading branch information
bamotav authored Oct 29, 2020
2 parents 658f671 + 2357643 commit ed89664
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 54 deletions.
Binary file removed samples/Hangfire.Sample/HangfireSampleDb
Binary file not shown.
10 changes: 6 additions & 4 deletions src/Hangfire.RecurringJobAdmin/Core/JobAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Hangfire.RecurringJobAdmin.Core
{
public static class JobAgent
{
private const string tagRecurringJob = "recurring-job";
private const string tagStopJob = "recurring-jobs-stop";
public const string tagRecurringJob = "recurring-job";
public const string tagStopJob = "recurring-jobs-stop";
public static void StartBackgroundJob(string JobId)
{
using (var connection = JobStorage.Current.GetConnection())
Expand Down Expand Up @@ -122,16 +122,18 @@ public static List<PeriodicJob> GetAllJobStopped()
return outPut;
}

public static bool IsValidJobId(string jobId)
public static bool IsValidJobId(string jobId, string tag = tagRecurringJob)
{
var result = false;
using (var connection = JobStorage.Current.GetConnection())
{
var job = connection.GetAllEntriesFromHash($"{tagRecurringJob}:{jobId}");
var job = connection.GetAllEntriesFromHash($"{tag}:{jobId}");

result = job != null;
}
return result;
}


}
}
43 changes: 0 additions & 43 deletions src/Hangfire.RecurringJobAdmin/Core/ReflectionHelper.cs

This file was deleted.

19 changes: 12 additions & 7 deletions src/Hangfire.RecurringJobAdmin/PeriodicJobBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal static class PeriodicJobBuilder
{
internal static void GetAllJobs()
{
var _registry = new RecurringJobRegistry();

foreach (var assembly in StorageAssemblySingleton.GetInstance().currentAssembly)
{
foreach (var type in assembly.GetTypes())
Expand All @@ -27,14 +29,17 @@ internal static void GetAllJobs()
var attr = method.GetCustomAttribute<RecurringJobAttribute>();
}

var _registry = new RecurringJobRegistry();
if(!JobAgent.IsValidJobId(attribute.RecurringJobId) && !JobAgent.IsValidJobId(attribute.RecurringJobId, JobAgent.tagStopJob))
{
_registry.Register(
attribute.RecurringJobId,
method,
attribute.Cron,
string.IsNullOrEmpty(attribute.TimeZone) ? TimeZoneInfo.Utc : TimeZoneInfo.FindSystemTimeZoneById(attribute.TimeZone),
attribute.Queue ?? EnqueuedState.DefaultQueue);
}

_registry.Register(
attribute.RecurringJobId,
method,
attribute.Cron,
string.IsNullOrEmpty(attribute.TimeZone) ? TimeZoneInfo.Utc : TimeZoneInfo.FindSystemTimeZoneById(attribute.TimeZone),
attribute.Queue ?? EnqueuedState.DefaultQueue);

}
}
}
Expand Down

0 comments on commit ed89664

Please sign in to comment.