Skip to content

Commit

Permalink
Support agenda 2 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkwolfe authored and joeframbach committed Feb 25, 2019
1 parent 873b11a commit 3c10e89
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ before_script:
- 'if [ "$AGENDA_VERSION" ]; then yarn add agenda@$AGENDA_VERSION; fi'
- 'until nc -z 127.0.0.1 27017 ; do echo Waiting for MongoDB; sleep 1; done'
env:
- AGENDA_VERSION=^1.0.0
- AGENDA_VERSION=^2.0.0
35 changes: 23 additions & 12 deletions lib/agendash.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ module.exports = function(agenda, options) {
return callback('Jobs not found');
}
async.series(jobs.map(job => done => {
const newJob = agenda.create(job.name, job.data).save(() => {
const newJob = agenda.create(job.name, job.data);
newJob.save()
.then(() => {
done(null, newJob);
})
.catch(err => {
done(err);
});
}), (err, results) => {
callback(err, results);
Expand All @@ -236,12 +241,17 @@ module.exports = function(agenda, options) {
}
try {
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');
}
callback();
});
agenda.cancel({_id: {$in: jobIds.map(jobId => collection.s.pkFactory(jobId))}})
.then(deleted => {
if (deleted) {
callback();
} else {
callback('Jobs not deleted');
}
})
.catch(err => {
callback(err);
});
} catch (err) {
callback(err.message);
}
Expand All @@ -264,12 +274,13 @@ module.exports = function(agenda, options) {
} else {
return callback('Jobs not created');
}
job.save(err => {
if (err) {
job.save()
.then(() => {
callback();
})
.catch(() => {
return callback('Jobs not created');
}
callback();
});
});
} catch (err) {
callback(err.message);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"homepage": "https://github.com/agenda/agendash#readme",
"license": "MIT",
"dependencies": {
"agenda": "^1.0.3",
"agenda": "^2.0.0",
"async": "^2.6.0",
"body-parser": "^1.15.0",
"commander": "^2.9.0",
Expand Down
22 changes: 14 additions & 8 deletions test/test-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ test.serial('POST /api/jobs/create should confirm the job exists', async t => {
});

test.serial('POST /api/jobs/delete should delete the job', async t => {
const job = await new Promise(resolve => {
const job = await new Promise((resolve, reject) => {
agenda.create('Test Job', {})
.schedule('in 4 minutes')
.save(async (err, job) => {
t.ifError(err);
return resolve(job);
.save()
.then(job => {
resolve(job);
})
.catch(err => {
reject(err);
});
});

Expand All @@ -70,12 +73,15 @@ test.serial('POST /api/jobs/delete should delete the job', async t => {
});

test.serial('POST /api/jobs/requeue should requeue the job', async t => {
const job = await new Promise(resolve => {
const job = await new Promise((resolve, reject) => {
agenda.create('Test Job', {})
.schedule('in 4 minutes')
.save(async (err, job) => {
t.ifError(err);
return resolve(job);
.save()
.then(job => {
resolve(job);
})
.catch(err => {
reject(err);
});
});

Expand Down
22 changes: 14 additions & 8 deletions test/test-hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ test.serial('POST /api/jobs/create should confirm the job exists', async t => {
});

test.serial('POST /api/jobs/delete should delete the job', async t => {
const job = await new Promise(resolve => {
const job = await new Promise((resolve, reject) => {
agenda.create('Test Job', {})
.schedule('in 4 minutes')
.save(async (err, job) => {
t.ifError(err);
return resolve(job);
.save()
.then(job => {
resolve(job);
})
.catch(err => {
reject(err);
});
});

Expand All @@ -76,12 +79,15 @@ test.serial('POST /api/jobs/delete should delete the job', async t => {
});

test.serial('POST /api/jobs/requeue should requeue the job', async t => {
const job = await new Promise(resolve => {
const job = await new Promise((resolve, reject) => {
agenda.create('Test Job', {})
.schedule('in 4 minutes')
.save(async (err, job) => {
t.ifError(err);
return resolve(job);
.save()
.then(job => {
resolve(job);
})
.catch(err => {
reject(err);
});
});

Expand Down

0 comments on commit 3c10e89

Please sign in to comment.