Skip to content

Commit

Permalink
fix(backend): properly trigger new job
Browse files Browse the repository at this point in the history
  • Loading branch information
Thundernerd committed Jan 2, 2024
1 parent 99a4fcc commit 5b4839a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public override async Task HandleAsync(JobsScheduleRequest req, CancellationToke
continue;
}

// Also pretty poor way of filtering this
if (trigger.JobKey.Name.EndsWith("-now", StringComparison.OrdinalIgnoreCase))
{
continue;
}

IJobDetail? jobDetail = await scheduler.GetJobDetail(trigger.JobKey, ct);

if (jobDetail == null)
Expand Down
12 changes: 10 additions & 2 deletions src/Mangarr.Backend/Endpoints/Jobs/Trigger/JobsTriggerEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class JobsTriggerEndpoint : Endpoint<JobsTriggerRequest, JobsTriggerRespo

public override void Configure()
{
Post("/jobs/{group}/{name}/trigger");
Get("/jobs/{group}/{name}/trigger");
AllowAnonymous();
}

Expand All @@ -28,7 +28,15 @@ public override async Task HandleAsync(JobsTriggerRequest req, CancellationToken
return;
}

await scheduler.ScheduleJob(trigger, ct);
ITrigger newTrigger = TriggerBuilder.Create()
.WithIdentity(new TriggerKey(req.Name + "-now", req.Group))
.WithDescription(trigger.Description)
.ForJob(trigger.JobKey)
.UsingJobData(trigger.JobDataMap)
.StartAt(DateTimeOffset.UtcNow.AddSeconds(5))
.Build();

await scheduler.ScheduleJob(newTrigger, ct);
await SendOkAsync(ct);
}
}

0 comments on commit 5b4839a

Please sign in to comment.