You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.2 KiB
77 lines
2.2 KiB
// admin/job-queue.js
|
|
// Copyright (C) 2021 Digital Telepresence, LLC
|
|
// License: Apache-2.0
|
|
|
|
'use strict';
|
|
|
|
const DTP_COMPONENT_NAME = 'admin:job-queue';
|
|
const express = require('express');
|
|
|
|
const { /*SiteError,*/ SiteController } = require('../../../lib/site-lib');
|
|
|
|
class JobQueueController extends SiteController {
|
|
|
|
constructor (dtp) {
|
|
super(dtp, DTP_COMPONENT_NAME);
|
|
}
|
|
|
|
async start ( ) {
|
|
const router = express.Router();
|
|
router.use(async (req, res, next) => {
|
|
res.locals.currentView = 'admin';
|
|
res.locals.adminView = 'job-queue';
|
|
return next();
|
|
});
|
|
|
|
router.param('jobQueueName', this.populateJobQueueName.bind(this));
|
|
|
|
router.get('/:jobQueueName', this.getJobQueueView.bind(this));
|
|
router.get('/', this.getHomeView.bind(this));
|
|
|
|
return router;
|
|
}
|
|
|
|
async populateJobQueueName (req, res, next, jobQueueName) {
|
|
const { jobQueue: jobQueueService } = this.dtp.services;
|
|
try {
|
|
res.locals.queueName = jobQueueName;
|
|
res.locals.queue = await jobQueueService.getJobQueue(jobQueueName);
|
|
return next();
|
|
} catch (error) {
|
|
this.log.error('failed to populate job queue', { jobQueueName, error });
|
|
return next(error);
|
|
}
|
|
}
|
|
|
|
async getJobQueueView (req, res, next) {
|
|
try {
|
|
res.locals.jobCounts = await res.locals.queue.getJobCounts();
|
|
res.locals.jobs = {
|
|
waiting: await res.locals.queue.getWaiting(0, 5),
|
|
active: await res.locals.queue.getActive(0, 5),
|
|
delayed: await res.locals.queue.getDelayed(0, 5),
|
|
failed: await res.locals.queue.getFailed(0, 5),
|
|
};
|
|
res.render('admin/job-queue/queue-view');
|
|
} catch (error) {
|
|
this.log.error('failed to populate job queue view', { error });
|
|
return next(error);
|
|
}
|
|
}
|
|
|
|
async getHomeView (req, res, next) {
|
|
const { jobQueue: jobQueueService } = this.dtp.services;
|
|
try {
|
|
res.locals.queues = await jobQueueService.discoverJobQueues('soapy:*:id');
|
|
res.render('admin/job-queue/index');
|
|
} catch (error) {
|
|
this.log.error('failed to populate job queues view', { error });
|
|
return next(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = async (dtp) => {
|
|
let controller = new JobQueueController(dtp);
|
|
return controller;
|
|
};
|