fix removable tasks
This commit is contained in:
@@ -59,7 +59,7 @@ const mail = {
|
||||
}
|
||||
return email.send(msg)
|
||||
.catch(e => {
|
||||
debug('Error sending email =>', e)
|
||||
debug('Error sending email =>', e.toString())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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' } })
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user