diff --git a/server/api/mail.js b/server/api/mail.js index 2837c8a3..fe2aee54 100644 --- a/server/api/mail.js +++ b/server/api/mail.js @@ -59,7 +59,7 @@ const mail = { } return email.send(msg) .catch(e => { - debug('Error sending email =>', e) + debug('Error sending email =>', e.toString()) }) } } diff --git a/server/notifier.js b/server/notifier.js index 63ec53e3..40d7ee20 100644 --- a/server/notifier.js +++ b/server/notifier.js @@ -1,14 +1,15 @@ const mail = require('./api/mail') -// const bot = require('./api/controller/fediverse') const config = require('config') const debug = require('debug')('notifier') const fediverseHelpers = require('./federation/helpers') -const { event: Event, notification: Notification, event_notification: EventNotification, +const { + event: Event, notification: Notification, event_notification: EventNotification, user: User, place: Place, tag: Tag, ap_user: APUser } = require('./api/models') const eventController = require('./api/controller/event') const notifier = { + sendNotification (notification, event) { const promises = [] debug('Send %s notification %s', notification.type, notification.action) @@ -26,6 +27,7 @@ const notifier = { } return Promise.all(promises) }, + async notifyEvent (action, eventId) { const event = await Event.findByPk(eventId, { include: [Tag, Place, Notification, { model: User }] @@ -51,6 +53,7 @@ const notifier = { }) return Promise.all(promises) }, + async notify () { // get all event notification in queue const eventNotifications = await EventNotification.findAll({ where: { status: 'new' } }) diff --git a/server/taskManager.js b/server/taskManager.js index cc07bd14..1e173a9e 100644 --- a/server/taskManager.js +++ b/server/taskManager.js @@ -22,9 +22,11 @@ class Task { const ret = this.method.apply(this, this.args) if (ret && typeof ret.then === 'function') { ret.catch(e => debug('TASK ERROR ', this.name, e)) + return ret } } catch (e) { debug('TASK ERROR ', this.name, e) + return Promise.resolve(false) } } } @@ -65,17 +67,10 @@ class TaskManager { if (!this.tasks.length) { return } - - this.tasks = this.tasks - .filter(async task => { - if (task.removable) { - await task.process() - } else { - return task - } - }) - - return Promise.all(this.tasks.map(task => task.process())) + const removableTasks = this.tasks.filter(t => t.removable).map(t => t.process()) + this.tasks = this.tasks.filter(t => !t.removable) + const tasks = this.tasks.map(t => t.process()) + return Promise.all(tasks.concat(removableTasks)) } async tick () { diff --git a/yarn.lock b/yarn.lock index 9ce62fd3..45b87730 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3985,10 +3985,10 @@ eslint-ast-utils@^1.1.0: lodash.get "^4.4.2" lodash.zip "^4.2.0" -eslint-config-prettier@^6.9.0: - version "6.9.0" - resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.9.0.tgz#430d24822e82f7deb1e22a435bfa3999fae4ad64" - integrity sha512-k4E14HBtcLv0uqThaI6I/n1LEqROp8XaPu6SO9Z32u5NlGRC07Enu1Bh2KEFw4FNHbekH8yzbIU9kUGxbiGmCA== +eslint-config-prettier@^6.10.0: + version "6.10.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.10.0.tgz#7b15e303bf9c956875c948f6b21500e48ded6a7f" + integrity sha512-AtndijGte1rPILInUdHjvKEGbIV06NuvPrqlIEaEaWtbtvJh464mDeyGMdZEQMsGvC0ZVkiex1fSNcC4HAbRGg== dependencies: get-stdin "^6.0.0" @@ -7938,10 +7938,10 @@ pg-packet-stream@^1.1.0: resolved "https://registry.yarnpkg.com/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz#e45c3ae678b901a2873af1e17b92d787962ef914" integrity sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg== -pg-pool@^2.0.9: - version "2.0.9" - resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.9.tgz#7ed69a27e204f99e9804a851404db6aa908a6dea" - integrity sha512-gNiuIEKNCT3OnudQM2kvgSnXsLkSpd6mS/fRnqs6ANtrke6j8OY5l9mnAryf1kgwJMWLg0C1N1cYTZG1xmEYHQ== +pg-pool@^2.0.10: + version "2.0.10" + resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.10.tgz#842ee23b04e86824ce9d786430f8365082d81c4a" + integrity sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg== pg-types@^2.1.0: version "2.2.0" @@ -7954,16 +7954,16 @@ pg-types@^2.1.0: postgres-date "~1.0.4" postgres-interval "^1.1.0" -pg@^7.17.1: - version "7.17.1" - resolved "https://registry.yarnpkg.com/pg/-/pg-7.17.1.tgz#1eb4d900e1f21f43978b306972b02a2329138755" - integrity sha512-SYWEip6eADsgDQIZk0bmB2JDOrC8Xu6z10KlhlXl03NSomwVmHB6ZTVyDCwOfT6bXHI8QndJdk5XxSSRXikaSA== +pg@^7.18.1: + version "7.18.1" + resolved "https://registry.yarnpkg.com/pg/-/pg-7.18.1.tgz#67f59c47a99456fcb34f9fe53662b79d4a992f6d" + integrity sha512-1KtKBKg/zWrjEEv//klBbVOPGucuc7HHeJf6OEMueVcUeyF3yueHf+DvhVwBjIAe9/97RAydO/lWjkcMwssuEw== dependencies: buffer-writer "2.0.0" packet-reader "1.0.0" pg-connection-string "0.1.3" pg-packet-stream "^1.1.0" - pg-pool "^2.0.9" + pg-pool "^2.0.10" pg-types "^2.1.0" pgpass "1.x" semver "4.3.2"