Skip to content

Commit

Permalink
Merge branch 'master' into add-xo
Browse files Browse the repository at this point in the history
  • Loading branch information
simison committed Jan 26, 2018
2 parents 7accaa5 + 7b84319 commit c99f904
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Next
====

* (koresar) Fix 404 errors when deleting and re-queuing jobs (#61)

0.4.0 / 2016-10-27
==================

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Agendash
[![Build Status](https://travis-ci.org/agenda/agendash.svg)](https://travis-ci.org/agenda/agendash)
<a href="https://slackin-ekwifvcwbr.now.sh/"><img src="https://slackin-ekwifvcwbr.now.sh/badge.svg" alt="Slack Status"></a>

A Dashboard for [Agenda](https://github.com/rschmukler/agenda)

Expand Down Expand Up @@ -51,6 +52,12 @@ or like this, for default collection `agendaJobs` and default port `3000`:
./node_modules/.bin/agendash --db=mongodb://localhost/agendaDb
```

If you are using npm >= 5.2, then you can use [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b):

```bash
npx agendash --db=mongodb://localhost/agendaDb --collection=agendaCollection --port=3001
```

### Middleware usage

Agendash provides Express middleware you can use at a specified path, for example this will
Expand Down Expand Up @@ -103,6 +110,8 @@ app.use('/agendash', Agendash(agenda, {
}));
```

Note that if you use a CSRF protection middleware like [`csurf`](https://www.npmjs.com/package/csurf), you might need to [configure it off](https://github.com/agenda/agendash/issues/23#issuecomment-270917949) for Agendash-routes.

### Additional options

The second argument to Agendash is an optional object. Valid keys are:
Expand Down
15 changes: 10 additions & 5 deletions lib/agendash.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = function(agenda, options) {
options = options || {};

agenda.on('ready', () => {
agenda._collection.createIndexes([
const collection = agenda._collection.collection || agenda._collection;
collection.createIndexes([
{key: {nextRunAt: -1, lastRunAt: -1, lastFinishedAt: -1}},
{key: {name: 1, nextRunAt: -1, lastRunAt: -1, lastFinishedAt: -1}}
], err => {
Expand Down Expand Up @@ -38,6 +39,7 @@ module.exports = function(agenda, options) {
const limit = 200; // @TODO: UI param
const skip = 0; // @TODO: UI param

const collection = agenda._collection.collection || agenda._collection;
agenda._collection.aggregate([
{$match: preMatch},
{$sort: {
Expand Down Expand Up @@ -97,7 +99,8 @@ module.exports = function(agenda, options) {
};

const getOverview = callback => {
agenda._collection.aggregate([
const collection = agenda._collection.collection || agenda._collection;
collection.aggregate([
{$project: {
_id: 0,
name: '$name',
Expand Down Expand Up @@ -207,8 +210,9 @@ module.exports = function(agenda, options) {
return callback('Agenda instance is not ready');
}
try {
agenda._collection
.find({_id: {$in: jobIds.map(jobId => agenda._collection.s.pkFactory(jobId))}})
const collection = agenda._collection.collection || agenda._collection;
collection
.find({_id: {$in: jobIds.map(jobId => collection.s.pkFactory(jobId))}})
.toArray((err, jobs) => {
if (err || jobs.length === 0) {
return callback('Jobs not found');
Expand All @@ -231,7 +235,8 @@ module.exports = function(agenda, options) {
return callback('Agenda instance is not ready');
}
try {
agenda.cancel({_id: {$in: jobIds.map(jobId => agenda._collection.s.pkFactory(jobId))}}, (err, deleted) => {
const collection = agenda._collection.collection || agenda._collection;
agenda.cancel({_id: {$in: jobIds.map(jobId => collection.s.pkFactory(jobId))}}, (err, deleted) => {
if (err || !deleted) {
callback('Jobs not deleted');
}
Expand Down

0 comments on commit c99f904

Please sign in to comment.