2020-01-14 13:35:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
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;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using MongoDB.Driver.Linq;
|
|
|
|
|
using Wabbajack.BuildServer.Models;
|
|
|
|
|
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>
|
|
|
|
|
{
|
|
|
|
|
public Jobs(ILogger<Jobs> logger, DBContext db) : base(logger, db)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("unfinished")]
|
|
|
|
|
public async Task<IEnumerable<Job>> GetUnfinished()
|
|
|
|
|
{
|
|
|
|
|
return await Db.Jobs.AsQueryable()
|
|
|
|
|
.Where(j => j.Ended == null)
|
|
|
|
|
.OrderByDescending(j => j.Priority)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
2020-01-14 13:35:50 +00:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("enqueue_job/{JobName}")]
|
|
|
|
|
public async Task<string> EnqueueJob(string JobName)
|
|
|
|
|
{
|
|
|
|
|
var jobtype = AJobPayload.NameToType[JobName];
|
|
|
|
|
var job = new Job{Priority = Job.JobPriority.High, Payload = (AJobPayload)jobtype.GetConstructor(new Type[0]).Invoke(new object?[0])};
|
|
|
|
|
await Db.Jobs.InsertOneAsync(job);
|
|
|
|
|
return job.Id;
|
|
|
|
|
}
|
2020-01-08 04:41:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|