Skip to content

Instantly share code, notes, and snippets.

@MiguelCedric
Created March 8, 2018 20:51
Show Gist options
  • Save MiguelCedric/895b1dc89db54bbf2505de5d2167acb1 to your computer and use it in GitHub Desktop.
Save MiguelCedric/895b1dc89db54bbf2505de5d2167acb1 to your computer and use it in GitHub Desktop.
Archive ride job
// Sendgrid API
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const MongoClient = require('mongodb').MongoClient;
module.exports = function(agenda) {
agenda.define('archive ride', function(job, done) {
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/yourdatabase", function(err, db) {
if(!err) {
db.collection('rides').findOneAndUpdate({_id: job.attrs.data.rideId},
{ $set: { status: 'expired' }}, function (err) {
if(!err) {
done();
}
})
}
if(err) {
console.log(err);
done();
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment