From 4d91b26537c9b9747df777a1e27bf4c80f31dc9b Mon Sep 17 00:00:00 2001 From: bernat Date: Fri, 20 Nov 2020 13:35:01 +0100 Subject: [PATCH] checkinbox moved to worker --- back/model-config.json | 6 ------ back/models/worker-time-control-params.js | 3 --- .../back/methods/worker-time-control-mail}/checkInbox.js | 4 ++++ modules/worker/back/model-config.json | 6 ++++++ modules/worker/back/models/worker-time-control-mail.js | 3 +++ .../worker/back}/models/worker-time-control-mail.json | 0 .../worker/back}/models/worker-time-control-params.json | 0 7 files changed, 13 insertions(+), 9 deletions(-) delete mode 100644 back/models/worker-time-control-params.js rename {back/methods/imap-time-control => modules/worker/back/methods/worker-time-control-mail}/checkInbox.js (97%) create mode 100644 modules/worker/back/models/worker-time-control-mail.js rename {back => modules/worker/back}/models/worker-time-control-mail.json (100%) rename {back => modules/worker/back}/models/worker-time-control-params.json (100%) diff --git a/back/model-config.json b/back/model-config.json index da9feaa1f..f0032edab 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -76,12 +76,6 @@ }, "UserLog": { "dataSource": "vn" - }, - "WorkerTimeControlParams": { - "dataSource": "vn" - }, - "WorkerTimeControlMail": { - "dataSource": "vn" } } diff --git a/back/models/worker-time-control-params.js b/back/models/worker-time-control-params.js deleted file mode 100644 index c71d4c237..000000000 --- a/back/models/worker-time-control-params.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - require('../methods/imap-time-control/checkInbox')(Self); -}; diff --git a/back/methods/imap-time-control/checkInbox.js b/modules/worker/back/methods/worker-time-control-mail/checkInbox.js similarity index 97% rename from back/methods/imap-time-control/checkInbox.js rename to modules/worker/back/methods/worker-time-control-mail/checkInbox.js index 9411b95e5..fa42f8135 100644 --- a/back/methods/imap-time-control/checkInbox.js +++ b/modules/worker/back/methods/worker-time-control-mail/checkInbox.js @@ -35,6 +35,10 @@ module.exports = Self => { imap.once('ready', function() { openInbox(function(err, box) { if (err) throw err; + const totalMessages = box.messages.total; + if (totalMessages == 0) + imap.end(); + let f = imap.seq.fetch('1:*', { bodies: ['HEADER.FIELDS (FROM SUBJECT)', '1'], struct: true diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 7a498fce7..e35e39721 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -55,6 +55,12 @@ }, "WorkerLog": { "dataSource": "vn" + }, + "WorkerTimeControlParams": { + "dataSource": "vn" + }, + "WorkerTimeControlMail": { + "dataSource": "vn" } } diff --git a/modules/worker/back/models/worker-time-control-mail.js b/modules/worker/back/models/worker-time-control-mail.js new file mode 100644 index 000000000..36f3851b6 --- /dev/null +++ b/modules/worker/back/models/worker-time-control-mail.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/worker-time-control-mail/checkInbox')(Self); +}; diff --git a/back/models/worker-time-control-mail.json b/modules/worker/back/models/worker-time-control-mail.json similarity index 100% rename from back/models/worker-time-control-mail.json rename to modules/worker/back/models/worker-time-control-mail.json diff --git a/back/models/worker-time-control-params.json b/modules/worker/back/models/worker-time-control-params.json similarity index 100% rename from back/models/worker-time-control-params.json rename to modules/worker/back/models/worker-time-control-params.json