Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic implementation is broken #20

Open
niftylettuce opened this issue Nov 25, 2015 · 5 comments
Open

Basic implementation is broken #20

niftylettuce opened this issue Nov 25, 2015 · 5 comments

Comments

@niftylettuce
Copy link

This is extremely bad practice to use app.use and to create your own express() instance.

The API should be modularized and exposed so that users can easily plug this into their existing apps.

@niftylettuce
Copy link
Author

Am I the only one that cares or realizes your basic documentation doesn't even work?

@dylanjha
Copy link

dylanjha commented Dec 3, 2015

@niftylettuce I'm just running into this. Did you manage to mount it in your existing app with an existing agenda instance?

@niftylettuce
Copy link
Author

@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 [email protected] and I'll notify you when my app is released that is a replacement for agenda-ui 👍

@dylanjha
Copy link

dylanjha commented Dec 3, 2015

thanks @niftylettuce! I'll try this out, and yes I'm definitely interested in a replacement for agenda-ui, will send an email

@simison
Copy link

simison commented Feb 20, 2016

@niftylettuce any updates? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants