Skip to content

Instantly share code, notes, and snippets.

@billjohnston
Created January 4, 2014 00:29
Show Gist options
  • Save billjohnston/8249600 to your computer and use it in GitHub Desktop.
Save billjohnston/8249600 to your computer and use it in GitHub Desktop.
Make a scheduled node process w/ heroku scheduler
.DS_Store
node_modules/
.nodemonignore
var Mailgun = require('mailgun').Mailgun;
var mg = new Mailgun(process.env.MAILGUN_API_KEY);
mg.sendText('sender-email@fake.com', ['recipient-email@fake.com'],
'This is the subject',
'This is the text',
'noreply@fake.com', {},
function(err) {
if (err) console.log('Oh noes: ' + err);
else console.log('Success');
});
{
"name": "heroku_scheduler_test",
"version": "0.0.1",
"private": true,
"engines": {
"node": "0.10.x"
},
"dependencies": {
"mailgun": "*"
}
}
git init
git commit -am 'Initial commit'
heroku create
(optional, set env vars. access with 'process.env.MAILGUN_API_KEY')
heroku config:set MAILGUN_API_KEY=your_api_key
heroku addons:add scheduler
heroku addons:open scheduler
(This will open the heroku page to manage scheduled jobs. For this example you would put task:node mail with the desired frequency)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment