-
Notifications
You must be signed in to change notification settings - Fork 23
/
example.js
45 lines (40 loc) · 1016 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint-disable no-process-exit */
const config = require('./lib/config')
const notifier = require('.')
config.set({
"mongoUrl": 'mongodb://localhost/DemocracyOS-dev',
"defaultLocale": "es",
"mailer": {
"service": "gmail", // can be other provider
"auth": {
"user": "my-send-email@gmail.com",
"pass": "dont-commit-me!"
}
}
})
notifier.start()
.then(() => {
console.log('Executing job welcome-email')
return notifier.now('welcome-email', {
to: 'test-to-mail@whatever.com',
validateUrl: 'https://app.democracyos.org'
})
})
.then(() => {
return new Promise((resolve, reject) => {
notifier.agenda.once('success:welcome-email', (job) => {
resolve(job)
})
notifier.agenda.once('fail:welcome-email', (err, job) => {
reject(err)
})
})
})
.then((job) => {
console.log('User notified!', job.attrs)
process.exit(0)
})
.catch((err) => {
console.error('Error!', err)
process.exit(1)
})