Open niftylettuce opened 9 years ago
Am I the only one that cares or realizes your basic documentation doesn't even work?
@niftylettuce I'm just running into this. Did you manage to mount it in your existing app with an existing agenda instance?
@dylanjha actually what I did was just write my own connection and my own UI. It took 10 minutes.
Here's my script for client-side:
(function() {
var $jobs = $('#jobs');
// every 5 seconds poll for new jobs
setInterval(function() {
/*globals moment*/
$.getJSON('/admin/jobs/feed', {
date: moment().format('MM/DD/YY h:mm A')
}).done(function(jobs) {
if (jobs.length === 0)
return;
var html = window.templates.adminJobs_row({
jobs: jobs
});
$jobs.html(html);
}).fail(function() {
bootbox.alert('An error has occurred while loading data, this page will refresh', function() {
window.location.reload();
});
});
}, 5000);
}());
Here's my script for server-side:
var moment = require('moment');
var mongoose = require('mongoose');
var s = require('underscore.string');
var _ = require('underscore');
var lib;
module.exports = function(_lib) {
lib = _lib;
return exports;
};
exports.index = function index(req, res, next) {
res.render('admin/jobs', {
title: 'Admin - Jobs'
});
};
exports.feed = function feed(req, res, next) {
lib.db.model('Job')
.find({})
.sort('-_id -nextRunAt')
.lean()
.limit(10)
.exec(getJobs)
function getJobs(err, jobs) {
if (err) return next(err);
// then we need to only return the last 10
res.json(jobs);
}
};
Here's my view template:
extends ../../layout
append scripts
script(src='/js/templates/admin/jobs/_row.js')
script(src='/js/admin/jobs.js')
block content
include ../_menu
.container
.row
.col-md-12
.panel.panel-default
.panel-heading Jobs
table.table.table-striped
thead
tr
th ID
th Name
th Type
th Priority
th Next Run At
th Last Modified By
th Locked At
th Last Finished At
th Fail Reason
th Failed at
tbody#jobs
tr
td(colspan=10)
.text-center
i.fa.fa-spinner.fa-spin
Here's the row include that I require and pre-compile on client-side:
- var format = 'MM/DD/YY h:mm A';
each job in jobs
tr
td= job._id
td= job.name
td= job.type
td= job.priority
td= job.nextRunAt ? moment(job.nextRunAt).format(format) : ''
td= job.lastModifiedBy
td= job.lockedAt ? moment(job.lockedAt).format(format) : ''
td= job.lastFinishedAt ? moment(job.lastFinishedAt).format(format) : ''
td= job.failReason
td= job.failedAt ? moment(job.failedAt).format(format) : ''
It simply updates the list of jobs every 5 seconds with the 10 latest jobs, sorted by run at time. Could be improved. @dylanjha if you're interested, send me an email at niftylettuce@gmail.com and I'll notify you when my app is released that is a replacement for agenda-ui :+1:
thanks @niftylettuce! I'll try this out, and yes I'm definitely interested in a replacement for agenda-ui, will send an email
@niftylettuce any updates? :-)
This is extremely bad practice to use
app.use
and to create your ownexpress()
instance.The API should be modularized and exposed so that users can easily plug this into their existing apps.