Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done all #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ build/Release
# Dependency directories
node_modules
jspm_packages
dump.rdb

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.env
7 changes: 7 additions & 0 deletions alarm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

var cron = require('node-cron')

cron.schedule('* * * * *', function () {
console.log('running a task every minute')
})
42 changes: 42 additions & 0 deletions mail-listen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict'

const kue = require('kue')
const queue = kue.createQueue()
require('dotenv').config()

const sg = require('sendgrid')(process.env.SENDGRID_API_KEY)

queue.process('email', (job, done) => {
const request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: {
personalizations: [{
to: [{
email: job.data.to
}],
subject: job.data.content
}],
from: {
email: '[email protected]'
},
content: [{
type: 'text/plain',
value: job.data.content
}]
}
})

sg.API(request)
.then(response => {
console.log(response.statusCode)
console.log(response.body)
console.log(response.headers)
done()
})
.catch(error => {
// error is an instance of SendGridError
// The full response is attached to error.response
console.log(error.response.statusCode)
})
})
12 changes: 12 additions & 0 deletions mail-sender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

const kue = require('kue')
const queue = kue.createQueue()

let jobEmail = queue.create('email', {
to: '[email protected]',
subject: 'test',
content: 'Hello sendGrid'
}).save(function (err, title) {
if (err) console.log(err)
})
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "its-background-job",
"version": "1.0.0",
"description": "bakcground jobs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MrEi91/its-background-job.git"
},
"keywords": [
"redis",
"crons"
],
"author": "Eri Irawan",
"license": "ISC",
"bugs": {
"url": "https://github.com/MrEi91/its-background-job/issues"
},
"homepage": "https://github.com/MrEi91/its-background-job#readme",
"dependencies": {
"dotenv": "^4.0.0",
"kue": "^0.11.5",
"node-cron": "^1.1.3",
"sendgrid": "^4.8.2"
}
}