feat(notify): refs #6005 add restriction on created notification time
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
2421cc7c68
commit
ae25ba3fb6
|
@ -67,7 +67,7 @@ module.exports = Self => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newParams = Object.assign({}, queueParams, sendParams);
|
const newParams = Object.assign({}, queueParams, sendParams, {created: queue.created});
|
||||||
const email = new Email(queueName, newParams);
|
const email = new Email(queueName, newParams);
|
||||||
|
|
||||||
if (process.env.NODE_ENV != 'test')
|
if (process.env.NODE_ENV != 'test')
|
||||||
|
|
|
@ -80,8 +80,6 @@ fdescribe('Operator', () => {
|
||||||
|
|
||||||
console.log('lastNotification: ', lastNotification);
|
console.log('lastNotification: ', lastNotification);
|
||||||
|
|
||||||
expect(1).toEqual('Is already Notified');
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
|
@ -5,7 +5,7 @@ const name = 'backup-printer-selected';
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: name,
|
name: name,
|
||||||
async serverPrefetch() {
|
async serverPrefetch() {
|
||||||
const notifications = await this.rawSqlFromDef('previousNotifications', [name]);
|
const notifications = await this.rawSqlFromDef('previousNotifications', [name, this.created, this.created]);
|
||||||
if (!notifications.length || checkDuplicates(notifications, this.labelerId, this.sectorId))
|
if (!notifications.length || checkDuplicates(notifications, this.labelerId, this.sectorId))
|
||||||
throw new Error('Previous notification sended with the same parameters');
|
throw new Error('Previous notification sended with the same parameters');
|
||||||
|
|
||||||
|
@ -32,18 +32,21 @@ module.exports = {
|
||||||
workerId: {
|
workerId: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
created: {
|
||||||
|
type: Date,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkDuplicates(notifications, labelerFk, printerFk) {
|
function checkDuplicates(notifications, labelerFk, printerFk) {
|
||||||
const criteria = {
|
const criteria = {labelerId: labelerFk, sectorId: printerFk};
|
||||||
labelerId: labelerFk,
|
|
||||||
sectorId: printerFk
|
|
||||||
};
|
|
||||||
const filteredNotifications = notifications.filter(notification => {
|
const filteredNotifications = notifications.filter(notification => {
|
||||||
const paramsObj = JSON.parse(notification.params);
|
const paramsObj = JSON.parse(notification.params);
|
||||||
return Object.keys(criteria).every(key => criteria[key] === paramsObj[key]);
|
return Object.keys(criteria).every(key => criteria[key] === paramsObj[key]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return filteredNotifications.length > 1;
|
return filteredNotifications.length > 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,6 @@ SELECT nq.params, created, status
|
||||||
FROM util.notificationQueue nq
|
FROM util.notificationQueue nq
|
||||||
JOIN util.notification n ON n.name = nq.notificationFk
|
JOIN util.notification n ON n.name = nq.notificationFk
|
||||||
WHERE n.name = ?
|
WHERE n.name = ?
|
||||||
AND TIMESTAMPDIFF(SECOND, nq.created, util.VN_NOW()) <= n.delay
|
AND nq.created BETWEEN ? - INTERVAL IFNULL(n.delay, 0) SECOND AND ?
|
||||||
|
AND nq.status <> 'error'
|
||||||
|
ORDER BY created
|
|
@ -1,4 +0,0 @@
|
||||||
SELECT nq.params
|
|
||||||
FROM util.notificationQueue nq
|
|
||||||
JOIN util.notification n ON n.name = nq.notificationFk
|
|
||||||
WHERE n.name = ?
|
|
Loading…
Reference in New Issue