2020-01-14 13:35:50 +00:00
|
|
|
|
using System;
|
2020-01-08 04:41:50 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-01-16 05:06:25 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-01-08 04:41:50 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-03-10 20:41:45 +00:00
|
|
|
|
using Wabbajack.BuildServer.Model.Models;
|
2020-01-08 04:41:50 +00:00
|
|
|
|
using Wabbajack.BuildServer.Models.JobQueue;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.Controllers
|
|
|
|
|
{
|
2020-01-16 05:06:25 +00:00
|
|
|
|
[Authorize]
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("/jobs")]
|
|
|
|
|
public class Jobs : AControllerBase<Jobs>
|
|
|
|
|
{
|
2020-04-05 21:15:01 +00:00
|
|
|
|
public Jobs(ILogger<Jobs> logger, SqlService sql) : base(logger, sql)
|
2020-01-08 04:41:50 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 13:35:50 +00:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("enqueue_job/{JobName}")]
|
2020-03-29 02:42:18 +00:00
|
|
|
|
public async Task<long> EnqueueJob(string JobName)
|
2020-01-14 13:35:50 +00:00
|
|
|
|
{
|
|
|
|
|
var jobtype = AJobPayload.NameToType[JobName];
|
|
|
|
|
var job = new Job{Priority = Job.JobPriority.High, Payload = (AJobPayload)jobtype.GetConstructor(new Type[0]).Invoke(new object?[0])};
|
2020-04-05 21:15:01 +00:00
|
|
|
|
await SQL.EnqueueJob(job);
|
2020-01-14 13:35:50 +00:00
|
|
|
|
return job.Id;
|
|
|
|
|
}
|
2020-01-08 04:41:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|