Skip to content

Commit

Permalink
Fixed deps, Fixed README
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Sep 11, 2017
1 parent 67a5d0f commit 819d8f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ const agenda = new Agenda();
stopAgenda(agenda).then().catch(console.error);
```

> With advanced options including custom logger `logger`, cancel query `cancelQuery`, and check interval in milliseconds `checkIntervalMs`:
> With advanced options including custom cancel query `cancelQuery` and check interval in milliseconds `checkIntervalMs`:
```js
const stopAgenda = require('stop-agenda');
const Agenda = require('agenda');
const Logger = require('@ladjs/logger');

const agenda = new Agenda();

stopAgenda(agenda, {
logger: new Logger(),
cancelQuery: {
repeatInterval: {
$exists: true,
Expand All @@ -78,7 +76,6 @@ stopAgenda(agenda, {

```js
{
logger: console,
cancelQuery: {
repeatInterval: {
$exists: true,
Expand Down
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const Agenda = require('agenda');
const debug = require('debug')('stop-agenda');

const stopAgenda = (agenda, config = {}) => {
if (!(agenda instanceof Agenda))
if (typeof agenda !== 'object')
throw new Error('`agenda` must be an instance of Agenda');

config = Object.assign(
{
logger: console,
cancelQuery: {
repeatInterval: {
$exists: true,
Expand Down Expand Up @@ -36,17 +35,15 @@ const stopAgenda = (agenda, config = {}) => {
return reject(new Error('collection did not exist, see agenda#501'));
agenda.cancel(config.cancelQuery, (err, numRemoved) => {
if (err) return reject(err);
config.logger.info(`cancelled ${numRemoved} jobs`);
debug(`cancelled ${numRemoved} jobs`);
resolve();
});
}),
new Promise((resolve, reject) => {
// check every X ms for jobs still running
const jobInterval = setInterval(() => {
if (agenda._runningJobs.length > 0) {
config.logger.info(
`${agenda._runningJobs.length} jobs still running`
);
debug(`${agenda._runningJobs.length} jobs still running`);
} else {
clearInterval(jobInterval);
// cancel recurring jobs so they get redefined on next server start
Expand All @@ -56,6 +53,7 @@ const stopAgenda = (agenda, config = {}) => {
return reject(
new Error('collection did not exist, see agenda#501')
);
debug('attempting to run agenda.stop', agenda.stop);
agenda.stop(err => {
if (err) return reject(err);
resolve();
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"Nick Baugh <[email protected]> (http://niftylettuce.com/)"
],
"dependencies": {
"agenda": "^1.0.0"
"debug": "^3.0.1"
},
"devDependencies": {
"agenda": "^1.0.0",
"ava": "^0.22.0",
"codecov": "^2.3.0",
"cross-env": "^5.0.5",
Expand Down
8 changes: 7 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,12 @@ debug@^2.1.1, debug@^2.2.0, debug@^2.6.3, debug@^2.6.8:
dependencies:
ms "2.0.0"

debug@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.0.1.tgz#0564c612b521dc92d9f2988f0549e34f9c98db64"
dependencies:
ms "2.0.0"

debug@~0.7.2:
version "0.7.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-0.7.4.tgz#06e1ea8082c2cb14e39806e22e2f6f757f92af39"
Expand Down Expand Up @@ -3955,7 +3961,7 @@ remark-heading-gap@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/remark-heading-gap/-/remark-heading-gap-3.0.0.tgz#f52ac47a27995ef3248a59eb7544b5620b4736a6"

"remark-license@github:niftylettuce/remark-license":
remark-license@niftylettuce/remark-license:
version "4.0.1"
resolved "https://codeload.github.com/niftylettuce/remark-license/tar.gz/17ecb8f64f8f6082414d14f9267a12764e6ddbfb"
dependencies:
Expand Down

0 comments on commit 819d8f3

Please sign in to comment.