using System; using System.Linq; using System.Security.Policy; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; using Nancy; using Nettle; using Wabbajack.CacheServer.DTOs.JobQueue; namespace Wabbajack.CacheServer { public class JobQueueEndpoints : NancyModule { public JobQueueEndpoints() : base ("/jobs") { Get("/", HandleListJobs); } private readonly Func HandleListJobsTemplate = NettleEngine.GetCompiler().Compile(@"

Jobs - {{$.jobs.Count}} Pending

{{$.time}}

    {{each $.jobs}}
  1. {{$.Description}}
  2. {{/each}}
"); private async Task HandleListJobs(object arg) { var jobs = await Server.Config.JobQueue.Connect() .AsQueryable() .Where(j => j.Ended == null) .OrderByDescending(j => j.Priority) .ThenBy(j => j.Created) .ToListAsync(); var response = (Response)HandleListJobsTemplate(new {jobs, time = DateTime.Now}); response.ContentType = "text/html"; return response; } } }