Created
March 8, 2018 20:51
-
-
Save MiguelCedric/895b1dc89db54bbf2505de5d2167acb1 to your computer and use it in GitHub Desktop.
Archive ride job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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