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