Commit b243f784 authored by Phil Booth's avatar Phil Booth
Browse files

feat(jobs): send a final pre-death cheerio

parent 05f2e301
'use strict'
log = require '../log'
initialise = (transport, config, subjectPrefix) ->
log = log.initialise 'email/goodbye'
log.info 'initialising'
(event) ->
{ to, user, frequency, repo, paths } = event.getData()
text = """
Hey #{user},
This is your final email from GitHubReminder. My maker is turning me off and deleting my database. I will soon be dead.
My dying wish is to send one last reminder email that you may remember me by. I hope it's a belter.
Your starred repo of the death is called #{repo.name}.
Repository: #{repo.full_name}
Description: #{repo.description || ''}
Language: #{repo.language || ''}
Stars: #{repo.watchers_count}
Forks: #{repo.forks_count}
#{repo.html_url}
Cheerio,
the reminder bot.
"""
log.info "sending email to #{to}:"
console.log text
transport.sendMail {
from: config.from
to
subject: "#{subjectPrefix} Cheerio"
text
}, event.respond
module.exports = { initialise }
......@@ -13,7 +13,7 @@ events =
github: [ 'get-token', 'get-user', 'get-email', 'get-starred-recent', 'get-starred-all' ]
database: [ 'fetch', 'fetch-all', 'insert', 'update', 'delete' ]
jobs: [ 'generate', 'force' ]
email: [ 'send-reminder', 'send-error', 'send-verification', 'send-deletion' ]
email: [ 'send-reminder', 'send-error', 'send-verification', 'send-deletion', 'send-cheerio' ]
tokens: [ 'generate' ]
errors: [ 'report' ]
retrier: [ 'try' ]
......
......@@ -21,16 +21,15 @@ retryLimit = 10
initialise = ->
log = log.initialise 'jobs'
log.info 'initialising'
runDueJobs()
runFinalJobs()
clearExpiredVerifications()
eventBroker.subscribe 'jobs', eventHandlers
runDueJobs = ->
runFinalJobs = ->
eventBroker.publish events.database.fetchAll, {
type: 'users'
query:
job:
$lte: Date.now()
isSaved: true
verify:
$exists: false
}, (error, cursor) ->
......@@ -55,8 +54,6 @@ runDueJobs = ->
log.info "completed due job ##{index}"
setTimeout runDueJobs, jobFrequency
runJob = (error, user, after) ->
repos = repo = undefined
retryCount = 0
......@@ -93,7 +90,7 @@ runJob = (error, user, after) ->
unless user.unsubscribe
return getToken()
sendReminder()
sendFinalReminder()
getToken = ->
eventBroker.publish events.tokens.generate, null, updateUser
......@@ -107,9 +104,9 @@ runJob = (error, user, after) ->
unsubscribe: token
unset: {}
}, (error, result) ->
failOrContinue error, result, after, sendReminder
failOrContinue error, result, after, sendFinalReminder
sendReminder = ->
sendFinalReminder = ->
unsubscribe = "unsubscribe?user=#{user.name}&token=#{user.unsubscribe}"
sent = false
loop
......@@ -123,7 +120,7 @@ runJob = (error, user, after) ->
until: ->
sent
action: (done) ->
eventBroker.publish events.email.sendReminder, {
eventBroker.publish events.email.sendCheerio, {
to: user.email
user: user.name
frequency: user.frequency
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment