2023-03-24 Fred Gleason <fredg@paravelsystems.com>

* Refactored code in rdrssd(8) to improve reliability.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2023-03-24 16:35:40 -04:00
parent a6b410567d
commit 3b463992ec
2 changed files with 44 additions and 27 deletions

View File

@@ -24017,3 +24017,5 @@
2023-03-20 Fred Gleason <fredg@paravelsystems.com> 2023-03-20 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in 'RDCatchEvent::read()' that caused a segfault * Fixed a bug in 'RDCatchEvent::read()' that caused a segfault
when processing a 'Reload Decks' operation. when processing a 'Reload Decks' operation.
2023-03-24 Fred Gleason <fredg@paravelsystems.com>
* Refactored code in rdrssd(8) to improve reliability.

View File

@@ -2,7 +2,7 @@
// //
// Rivendell RSS Processor Service // Rivendell RSS Processor Service
// //
// (C) Copyright 2020-2022 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2020-2023 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as // it under the terms of the GNU General Public License version 2 as
@@ -133,9 +133,12 @@ void MainObject::ProcessFeed(const QString &key_name)
// //
// Update Posted XML // Update Posted XML
// //
rda->syslog(LOG_DEBUG,"examining feed \"%s\"",key_name.toUtf8().constData());
bool modified=false;
sql=QString("select ")+ sql=QString("select ")+
"`PODCASTS`.`ID`,"+ // 00 "`PODCASTS`.`ID`,"+ // 00
"`PODCASTS`.`EXPIRATION_DATETIME` "+ // 01 "`PODCASTS`.`EXPIRATION_DATETIME`,"+ // 01
"`ITEM_TITLE` "+ // 02
"from `PODCASTS` left join `FEEDS` "+ "from `PODCASTS` left join `FEEDS` "+
"on `PODCASTS`.`FEED_ID`=`FEEDS`.`ID` where "+ "on `PODCASTS`.`FEED_ID`=`FEEDS`.`ID` where "+
"(`FEEDS`.`KEY_NAME`='"+RDEscapeString(key_name)+"') && "+ "(`FEEDS`.`KEY_NAME`='"+RDEscapeString(key_name)+"') && "+
@@ -143,11 +146,17 @@ void MainObject::ProcessFeed(const QString &key_name)
"(`PODCASTS`.`EFFECTIVE_DATETIME`<"+now_str+") || "+ "(`PODCASTS`.`EFFECTIVE_DATETIME`<"+now_str+") || "+
"(`FEEDS`.`LAST_BUILD_DATETIME`<`PODCASTS`.`EXPIRATION_DATETIME`) && "+ "(`FEEDS`.`LAST_BUILD_DATETIME`<`PODCASTS`.`EXPIRATION_DATETIME`) && "+
"(`PODCASTS`.`EXPIRATION_DATETIME`<"+now_str+"))"; "(`PODCASTS`.`EXPIRATION_DATETIME`<"+now_str+"))";
// rda->syslog(LOG_NOTICE,"scanning feed %s: SQL: %s\n",
// key_name.toUtf8().constData(),sql.toUtf8().constData());
q=new RDSqlQuery(sql); q=new RDSqlQuery(sql);
while(q->next()) { while(q->next()) {
bool deleted=false; modified=true;
if((!q->value(1).isNull())&&(q->value(1).toDateTime()<now)) { if((!q->value(1).isNull())&&(q->value(1).toDateTime()<now)) {
// Delete expired cast //
// Delete expired item
//
RDPodcast *cast=new RDPodcast(rda->config(),q->value(0).toUInt()); RDPodcast *cast=new RDPodcast(rda->config(),q->value(0).toUInt());
if(!cast->dropAudio(feed,&err_msg,false)) { if(!cast->dropAudio(feed,&err_msg,false)) {
rda->syslog(LOG_WARNING, rda->syslog(LOG_WARNING,
@@ -157,44 +166,50 @@ void MainObject::ProcessFeed(const QString &key_name)
feed->keyName().toUtf8().constData(), feed->keyName().toUtf8().constData(),
err_msg.toUtf8().constData()); err_msg.toUtf8().constData());
} }
delete cast;
sql=QString("delete from `PODCASTS` where ")+ sql=QString("delete from `PODCASTS` where ")+
QString::asprintf("`ID`=%u",q->value(0).toUInt()); QString::asprintf("`ID`=%u",q->value(0).toUInt());
RDSqlQuery::apply(sql); RDSqlQuery::apply(sql);
rda->syslog(LOG_INFO,"purged cast %u [%s] from feed \"%s\"", rda->syslog(LOG_INFO,"purged cast %u [%s] from feed \"%s\"",
q->value(0).toUInt(),cast->itemTitle().toUtf8().constData(), q->value(0).toUInt(),q->value(2).toString().toUtf8().
constData(),
feed->keyName().toUtf8().constData()); feed->keyName().toUtf8().constData());
delete cast;
rda->ripc()->sendNotification(RDNotification::FeedType, rda->ripc()->sendNotification(RDNotification::FeedType,
RDNotification::ModifyAction,feed->keyName()); RDNotification::ModifyAction,feed->keyName());
rda->ripc()->sendNotification(RDNotification::FeedItemType, rda->ripc()->sendNotification(RDNotification::FeedItemType,
RDNotification::DeleteAction, RDNotification::DeleteAction,
q->value(0).toUInt()); q->value(0).toUInt());
deleted=true;
}
if(feed->postXml(&err_msg)) {
rda->syslog(LOG_DEBUG,
"repost of XML for feed \"%s\" triggered by cast id %u",
key_name.toUtf8().constData(),q->value(0).toUInt());
if(!deleted) {
rda->ripc()->sendNotification(RDNotification::FeedType,
RDNotification::ModifyAction,
feed->keyName());
rda->ripc()->sendNotification(RDNotification::FeedType,
RDNotification::ModifyAction,
feed->keyName());
}
} }
else { else {
rda-> //
syslog(LOG_WARNING, // Enable embargoed item
"repost of XML for feed \"%s\" triggered by cast id %u failed [%s]", //
key_name.toUtf8().constData(),q->value(0).toUInt(), rda->syslog(LOG_INFO,
err_msg.toUtf8().constData()); "auto-posting item for feed \"%s\": cast_id: %u, item_title: \"%s\"",
} key_name.toUtf8().constData(),q->value(0).toUInt(),
q->value(2).toString().toUtf8().constData());
rda->ripc()->sendNotification(RDNotification::FeedType,
RDNotification::ModifyAction,
feed->keyName());
rda->ripc()->sendNotification(RDNotification::FeedItemType,
RDNotification::ModifyAction,
q->value(0).toUInt());
}
} }
delete q; delete q;
//
// Update feed XML
//
if(modified) {
if(!feed->postXml(&err_msg)) {
rda->syslog(LOG_INFO,
"xml update FAILED for item in feed \"%s\" [%s]",
key_name.toUtf8().constData(),q->value(0).toUInt(),
err_msg.toUtf8().constData());
}
}
delete feed; delete feed;
} }