Permalink
Browse files

step version

  • Loading branch information...
seeker89 committed Aug 20, 2012
1 parent fafc894 commit 3f7c70876618078efa59027fb4f7015538ee6a51
Showing with 28 additions and 11 deletions.
  1. +2 −1 app/models/mailbox.coffee
  2. +26 −10 server.coffee
@@ -78,7 +78,7 @@ Mailbox.prototype.getMail = (boxname, constraints, c) ->
# so it looks coool, let's create a connection
server = new imap.ImapConnection
- username: mailbox.login + "_bug"
+ username: mailbox.login
password: mailbox.pass
host: mailbox.IMAP_server
port: mailbox.IMAP_port
@@ -131,6 +131,7 @@ Mailbox.prototype.getMail = (boxname, constraints, c) ->
console.log "nothing to download"
mailbox.IMAP_last_sync = new Date().toJSON()
server.logout()
+ callback()
# mails to fetch
else
View
@@ -14,14 +14,14 @@ if not module.parent
@jobs = @kue.createQueue()
- # @jobs.on "job complete", (id) ->
- # Job.get id, (error, job) ->
- # return if error
- # createCheckJob job.data.mb, 1000 * 60 * 0.5, (error) ->
- # return if error
- # job.remove (err) ->
- # throw err if err
- # console.log job.data.title + " #" + job.id + " complete job removed"
+ @jobs.on "job complete", (id) ->
+ Job.get id, (error, job) ->
+ return if error
+ createCheckJob job.data.mb, 1000 * 60 * 0.5, (error) ->
+ return if error
+ job.remove (err) ->
+ throw err if err
+ console.log job.data.title + " #" + job.id + " complete job removed"
#
# @jobs.on "job error", (id) ->
# Job.get id, (error, job) ->
@@ -58,9 +58,25 @@ if not module.parent
createCheckJobs()
@jobs.promote()
+
+ Step = require "step"
# KUE jobs
@jobs.process "check mailbox", 1, (job, done) ->
- console.log job.data.title + " #" + job.id + " job started"
- (Mailbox job.data.mailbox).getNewMail job.data.num, done
+ Step (prepare = ->
+ console.log job.data.title + " #" + job.id + " job started"
+ this()
+ ),
+ (fetch = (err) ->
+ console.log err if err
+ (Mailbox job.data.mailbox).getNewMail job.data.num, this
+ ),
+ (showIt = (err) ->
+ if err
+ console.log "KO: " + err
+ done "error"
+ else
+ console.log "OK"
+ done()
+ )

0 comments on commit 3f7c708

Please sign in to comment.