The name "Timers" is being replaced with "Temporal". This commit changes just the code (not project names/directories).
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Elsa.Activities.Temporal.Hangfire.Jobs;
|
|
using Elsa.Activities.Temporal.Hangfire.Models;
|
|
using Hangfire;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace Elsa.Activities.Temporal
|
|
{
|
|
public static class BackgroundJobClientExtensions
|
|
{
|
|
public static void ScheduleWorkflow(this IBackgroundJobClient backgroundJobClient, RunHangfireWorkflowJobModel data, DateTimeOffset dateTimeOffset)
|
|
{
|
|
backgroundJobClient.UnscheduleJobWhenAlreadyExists(data);
|
|
backgroundJobClient.Schedule<RunHangfireWorkflowJob>(job => job.ExecuteAsync(data), dateTimeOffset);
|
|
}
|
|
|
|
public static void UnscheduleJobWhenAlreadyExists(this IBackgroundJobClient backgroundJobClient, RunHangfireWorkflowJobModel data)
|
|
{
|
|
var identity = data.GetIdentity();
|
|
var monitor = JobStorage.Current.GetMonitoringApi();
|
|
var workflowJobType = typeof(RunHangfireWorkflowJob);
|
|
|
|
var jobs = monitor.ScheduledJobs(0, int.MaxValue)
|
|
.Where(x => x.Value.Job.Type == workflowJobType && ((RunHangfireWorkflowJobModel)x.Value.Job.Args[0]).GetIdentity() == identity);
|
|
|
|
foreach (var job in jobs)
|
|
{
|
|
BackgroundJob.Delete(job.Key);
|
|
}
|
|
}
|
|
}
|
|
}
|