40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using System.Data;
|
|
using FictionArchive.Service.SchedulerService.Models;
|
|
using FictionArchive.Service.SchedulerService.Services;
|
|
using FictionArchive.Service.Shared.Constants;
|
|
using HotChocolate.Authorization;
|
|
using HotChocolate.Types;
|
|
using Quartz;
|
|
|
|
namespace FictionArchive.Service.SchedulerService.GraphQL;
|
|
|
|
public class Mutation
|
|
{
|
|
[Error<DuplicateNameException>]
|
|
[Error<FormatException>]
|
|
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
|
public async Task<SchedulerJob> ScheduleEventJob(string key, string description, string eventType, string eventData, string cronSchedule, JobManagerService jobManager)
|
|
{
|
|
return await jobManager.ScheduleEventJob(key, description, eventType, eventData, cronSchedule);
|
|
}
|
|
|
|
[Error<JobPersistenceException>]
|
|
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
|
public async Task<bool> RunJob(string jobKey, JobManagerService jobManager)
|
|
{
|
|
return await jobManager.TriggerJob(jobKey);
|
|
}
|
|
|
|
[Error<KeyNotFoundException>]
|
|
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
|
public async Task<bool> DeleteJob(string jobKey, JobManagerService jobManager)
|
|
{
|
|
bool deleted = await jobManager.DeleteJob(jobKey);
|
|
if (!deleted)
|
|
{
|
|
throw new KeyNotFoundException($"Job with key '{jobKey}' was not found");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |