Hier ist ein ein Stück Code, der genau das macht, was der Worker auch macht.
Du könntest ihn durhc console.log angaben debuggen und dann analysiren, wo genau er fehlschlägt, vielleicht bekomst du auch eine genauere Fehlermeldung.
Du musst deine UUID eintragen.
Das ist alles aber schon sehr entwicklungslastig.
Hinweis: ich habe den ganzen Code der Version 11.13.0 entnommen.
Hinweis 2: Das hier ist die Suche, die der Worker nutzt um entsprechende Objekte zum verarbeiten zu finden:
Code
identifier_ci:agorum_composite_notification agorum_composite_notification_next_date_range:[* TO NOW] agorum_composite_notification_count:[0 TO *] agorum_composite_notification_interval:[0 TO *]
Code
/* global sc, sca */
let objects = require('common/objects');
let metadata = require('common/metadata');
let item = objects.find(9999); /*<= hier deine uuid rein*/
let data = {
uuid: item.UUID,
owner: item.owner
};
let mds = metadata.all(item, /^agorum_composite_notification_/);
data = Object.assign({}, data, mds);
console.log({
data: data
});
worker(data);
function worker(data) {
let obj = objects.tryFind(data.uuid);
// object does not exist anymore
if (!obj)
return;
let user = obj.owner;
/*
let query = cache.read(data.agorum_composite_notification_configuration + '_' + user.ID);
if (!query) {
query = searchUtils.buildQuery(data.agorum_composite_notification_configuration, user);
cache.write(data.agorum_composite_notification_configuration + '_' + user.ID, query);
}
*/
let queryWithSort = searchUtils.buildQueryWithSort(data.agorum_composite_notification_configuration, user);
let query = queryWithSort.query;
let sortAttribute = queryWithSort.sortAttribute;
let stickySuffix = data.agorum_composite_notification_configuration + ';' + user.UUID;
let sticky = 'Notification configuration error: ' + stickySuffix;
if (query) {
log.clearSticky(sticky);
} else {
// something went wrong in require-cache, print it out for debugging
log
.warning()
.detail(
'filter or search configuration not found: ' +
data.agorum_composite_notification_configuration +
'. There is a notification configuration for the user: ' +
user.name +
' (' +
user +
'), that is basing on a configuration, that is not present anymore. ' +
'To solve the problem you may delete the configuration with the id:' +
obj +
'\n\ncache structure:\n' +
Object.entries(require.cache)
.map(([key, value]) => key + ': ' + Object.keys(value.exports || {}).join(', '))
.join('\n'))
.object(obj)
.sticky(sticky)
.log(sticky);
// reset the script cache
Object.keys(require.cache).forEach(key => delete require.cache[key]);
// try again
queryWithSort = searchUtils.buildQueryWithSort(data.agorum_composite_notification_configuration, user);
query = queryWithSort.query;
sortAttribute = queryWithSort.sortAttribute;
}
if (!query) {
return;
}
let scUser = sc.asUser(user);
let objectsUser = objects.sc(scUser);
let lastSeen = common.formatDateLocale(data.agorum_composite_notification_lastseen, "yyyy-MM-dd'T'HH:mm:ss.S'Z'");
let baseQuery = query;
// filter out elements, for notifying
query =
'(' +
query +
') ' +
sortAttribute +
'_date_range:[' +
lastSeen +
' TO *] NOT ag_temporary:true NOT fromaddress:"' +
NOTIFY_IDENT +
'"';
sticky = 'Notification query failed: ' + stickySuffix;
let result;
try {
result = objectsUser
.query(query)
.sort(sortAttribute + ' desc')
.limit(1)
.search('uuid', sortAttribute);
log.clearSticky(sticky);
} catch (err) {
log
.error()
.object(obj)
.detail(
'query: ' + query,
'sortAttribute: ' + sortAttribute,
'configuration name: ' + data.agorum_composite_notification_configuration,
err)
.sticky(sticky)
.log(sticky);
return;
}
let total = result.total;
let lastUpdateDate = new Date(0);
let hasNewItems = false;
if (result.rows && result.rows[0]) {
lastUpdateDate = new Date(new Date(result.rows[0][sortAttribute]).getTime() + 1);
if (lastUpdateDate.getTime() > data.agorum_composite_notification_lastnotified.getTime()) {
hasNewItems = true;
}
}
// call notifier, when there are new items or the total has change (e.g. something was removed)
if (hasNewItems || data.agorum_composite_notification_count != total) {
let lastNotified = data.agorum_composite_notification_lastnotified || data.agorum_composite_notification_lastseen;
lastNotified = common.formatDateLocale(lastNotified, "yyyy-MM-dd'T'HH:mm:ss.S'Z'");
if (!hasNewItems) {
// no new items, so set the lastUpdateDate to the current value of lastNotified
lastUpdateDate = lastNotified;
}
metadata({
agorum_composite_notification_count: total,
agorum_composite_notification_lastnotified: lastUpdateDate,
}).save(obj);
// hand over to notify handler, to do something with the result
// do only, when user is not locked
if (user.lockState === 0) {
let typeSetting = loadType(data.agorum_composite_notification_type);
if (typeSetting && typeSetting.notify) {
/** @type {NotificationInfo} */
let notifyData = {
user: user,
scUser: scUser,
obj: obj,
data: data,
name: data.agorum_composite_notification_type,
rows: result.rows,
total: total,
query: baseQuery,
hasNew: hasNewItems,
lastSeen: lastSeen,
lastNotified: lastNotified,
sortAttribute: sortAttribute,
};
sticky = 'Notification script failed: ' + stickySuffix;
try {
typeSetting.notify(notifyData);
log.clearSticky(sticky);
} catch (err) {
log.error().object(obj).detail(notifyData, err).sticky(sticky).log(sticky);
}
}
}
} else {
objects.reIndex(obj);
}
}
Alles anzeigen