Check outgoing message for age before trying to re-send. This may avoid an issue if an article is causing a bug and keeping other articles from sending.

This commit is contained in:
Retro_Guy 2024-09-20 08:30:52 -07:00
parent bfa6457930
commit 9798a4b0d0
1 changed files with 12 additions and 10 deletions

View File

@ -28,7 +28,7 @@ include("$file_newsportal");
if ($CONFIG['remote_server'] == '') { if ($CONFIG['remote_server'] == '') {
exit(); exit();
} }
$logfile = $logdir . '/spoolnews.log'; $logfile = $logdir . '/send.log';
@mkdir($spooldir . "/" . $config_name, 0755, 'recursive'); @mkdir($spooldir . "/" . $config_name, 0755, 'recursive');
@ -55,19 +55,27 @@ echo "\nSend Done\r\n";
function post_articles($ns, $spooldir) function post_articles($ns, $spooldir)
{ {
global $logfile, $config_name; global $logfile, $config_name;
if (! is_dir($spooldir . "/" . $config_name . "/outgoing/")) {
return "No messages to send\r\n";
}
$outgoing_dir = $spooldir . "/" . $config_name . "/outgoing/"; $outgoing_dir = $spooldir . "/" . $config_name . "/outgoing/";
$fail_dir = $outgoing_dir . '/failed/'; $fail_dir = $outgoing_dir . '/failed/';
if (!is_dir($fail_dir)) { if (!is_dir($fail_dir)) {
mkdir($fail_dir); mkdir($fail_dir);
} }
if (! is_dir($outgoing_dir)) {
mkdir($outgoing_dir);
return "No messages to send\r\n";
}
$messages = scandir($outgoing_dir); $messages = scandir($outgoing_dir);
foreach ($messages as $message) { foreach ($messages as $message) {
if (! is_file($outgoing_dir . $message)) { if (! is_file($outgoing_dir . $message)) {
continue; continue;
} }
if (filemtime($outgoing_dir . $message) < (time() - 14400)) { // Stop trying to send article of over 4 hours old
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " POST Failed: Too many retries, giving up for: " . $message, FILE_APPEND);
rename($outgoing_dir . $message, $fail_dir . $message);
continue;
}
echo "Sending: " . $outgoing_dir . $message . "\r\n"; echo "Sending: " . $outgoing_dir . $message . "\r\n";
fputs($ns, "MODE READER\r\n"); fputs($ns, "MODE READER\r\n");
$response = line_read($ns); $response = line_read($ns);
@ -91,13 +99,7 @@ function post_articles($ns, $spooldir)
if (strcmp(substr($response, 0, 3), "441") == 0) { // Posting failed if (strcmp(substr($response, 0, 3), "441") == 0) { // Posting failed
if (strcmp(substr($response, 0, 6), "441 43") == 0) { // Article specifically rejected. Move to 'failed' if (strcmp(substr($response, 0, 6), "441 43") == 0) { // Article specifically rejected. Move to 'failed'
rename($outgoing_dir . $message, $fail_dir . $message); rename($outgoing_dir . $message, $fail_dir . $message);
} else { // Article may have failed for some other reason
// Keep retrying outgoing message for 4 hours in case of temporary issue
if (filemtime($outgoing_dir . $message) < (time() - 14400)) {
rename($outgoing_dir . $message, $fail_dir . $message);
}
} }
// file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " POST Failed: " . $response, FILE_APPEND);
} }
if (strcmp(substr($response, 0, 3), "240") == 0) { if (strcmp(substr($response, 0, 3), "240") == 0) {
$removed = unlink($outgoing_dir . $message); $removed = unlink($outgoing_dir . $message);