Skip to content

Commit

Permalink
Скрипт по удалению неактуальных новостей: добавление логгирования
Browse files Browse the repository at this point in the history
  • Loading branch information
norderus committed Dec 4, 2024
1 parent 0c74727 commit 817d9ba
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ontology/generic-function/veda-function-news.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ v-s:News_ActualDatesCheck_Daily
rdf:type v-s:Event ;
v-s:author cfg:VedaSystemAppointment ;
rdfs:label "Скрипт, убирающий неактуальные новости из списка публикаций" ;
v-s:triggerByUid cfg:daily ;
v-s:triggerByUid cfg:hourly ;
v-s:runAt "V8.LowPriority";
v-s:script """
print("****************************START v-s:News_ActualDatesCheck_Daily******************************");
var today = new Date();
var newsToRemove = [];
print("Current date: " + today);
// Получаем объект уведомлений
var clientNotification = get_individual(ticket, "cfg:ClientNotification");
Expand All @@ -194,8 +197,8 @@ if (!clientNotification || !clientNotification["rdf:value"]) {
return;
}
var today = new Date();
var newsToRemove = [];
var initialCount = clientNotification["rdf:value"].length;
print("Initial notifications count: " + initialCount);
// Проверяем каждую новость в списке уведомлений
for (var i = 0; i < clientNotification["rdf:value"].length; i++) {
Expand All @@ -209,6 +212,7 @@ for (var i = 0; i < clientNotification["rdf:value"].length; i++) {
}
var shouldRemove = false;
var dateInfo = "";
// Проверяем наличие дат
if (!news["v-s:dateTo"] || !news["v-s:dateFrom"]) {
Expand All @@ -223,6 +227,11 @@ for (var i = 0; i < clientNotification["rdf:value"].length; i++) {
// Если текущая дата больше dateTo или меньше dateFrom
if (today > dateTo || today < dateFrom) {
shouldRemove = true;
if (today > dateTo) {
dateInfo = " (expired on: " + dateTo + ")";
} else {
dateInfo = " (will be active from: " + dateFrom + ")";
}
}
}
Expand All @@ -235,7 +244,7 @@ for (var i = 0; i < clientNotification["rdf:value"].length; i++) {
"v-s:hasStatus": [veda.Util.newUri("v-s:StatusExecuted")]
};
set_in_individual(ticket, set_in_doc, _event_id);
print("News status updated: ", newsUri);
print("News status updated: ", newsUri, dateInfo);
}
} catch (err) {
print("Error processing news ", newsUri, ": ", err);
Expand All @@ -248,7 +257,10 @@ if (newsToRemove.length > 0) {
clientNotification["rdf:value"].splice(newsToRemove[j], 1);
}
set_in_individual(ticket, clientNotification, _event_id);
print("Removed ", newsToRemove.length, " outdated news from notifications");
var remainingCount = clientNotification["rdf:value"].length;
print("Summary:");
print("- Removed notifications: " + newsToRemove.length);
print("- Remaining notifications: " + remainingCount);
}
print("****************************END v-s:News_ActualDatesCheck_Daily******************************");
Expand Down

0 comments on commit 817d9ba

Please sign in to comment.