Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken authored and linkdotnet committed Oct 31, 2024
1 parent 159529e commit efa9e39
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/NCronJob/Registry/IInstantJobRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,8 @@ public void ForceRunInstantJob<TJob>(object? parameter = null, CancellationToken
private void RunDelegateJob(Delegate jobDelegate, DateTimeOffset startDate, bool forceExecution = false, CancellationToken token = default)
{
var definition = jobRegistry.AddDynamicJob(jobDelegate);
var run = JobRun.Create(definition);
run.Priority = JobPriority.High;
run.RunAt = startDate;
run.IsOneTimeJob = true;
run.CancellationToken = token;

if (forceExecution)
{
_ = jobWorker.InvokeJobWithSchedule(run, token);
}
else
{
var jobQueue = jobQueueManager.GetOrAddQueue(run.JobDefinition.JobFullName);
jobQueue.EnqueueForDirectExecution(run, startDate);
jobQueueManager.SignalJobQueue(run.JobDefinition.JobFullName);
}
RunInternal(definition, null, startDate, forceExecution, token);
}

private void RunJob<TJob>(DateTimeOffset startDate, object? parameter = null, bool forceExecution = false, CancellationToken token = default)
Expand All @@ -259,21 +245,31 @@ private void RunJob<TJob>(DateTimeOffset startDate, object? parameter = null, bo

token.Register(() => LogCancellationRequested(parameter));

var run = JobRun.Create(newJobDefinition, parameter, token);
run.Priority = JobPriority.High;
run.RunAt = startDate;
run.IsOneTimeJob = true;
RunInternal(newJobDefinition, parameter, startDate, forceExecution, token);
}
}

if (forceExecution)
{
_ = jobWorker.InvokeJobWithSchedule(run, token);
}
else
{
var jobQueue = jobQueueManager.GetOrAddQueue(run.JobDefinition.JobFullName);
jobQueue.EnqueueForDirectExecution(run, startDate);
jobQueueManager.SignalJobQueue(run.JobDefinition.JobFullName);
}
private void RunInternal(
JobDefinition jobDefinition,
object? parameter,
DateTimeOffset startDate,
bool forceExecution,
CancellationToken token)
{
var run = JobRun.Create(jobDefinition, parameter, token);
run.Priority = JobPriority.High;
run.RunAt = startDate;
run.IsOneTimeJob = true;

if (forceExecution)
{
_ = jobWorker.InvokeJobWithSchedule(run, token);
}
else
{
var jobQueue = jobQueueManager.GetOrAddQueue(run.JobDefinition.JobFullName);
jobQueue.EnqueueForDirectExecution(run, startDate);
jobQueueManager.SignalJobQueue(run.JobDefinition.JobFullName);
}
}

Expand Down

0 comments on commit efa9e39

Please sign in to comment.