diff options
-rw-r--r-- | update_daemon2.php | 96 | ||||
-rw-r--r-- | update_daemon_loop.php | 70 |
2 files changed, 72 insertions, 94 deletions
diff --git a/update_daemon2.php b/update_daemon2.php index e7b5aeb20..cf25eeac2 100644 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -85,11 +85,6 @@ "Maybe another daemon is already running.\n"); } - if (file_is_locked("update_daemon.lock")) { - die("error: Can't create lockfile. ". - "Maybe another daemon is already running.\n"); - } - if (!pcntl_fork()) { pcntl_signal(SIGINT, 'sigint_handler'); @@ -199,26 +194,49 @@ $login_thresh_qpart = ""; } + //if (DB_TYPE == "pgsql") { + // $update_limit_qpart = "AND ttrss_feeds.last_updated < NOW() - INTERVAL '".(DAEMON_SLEEP_INTERVAL*2)." seconds'"; + //} else { + // $update_limit_qpart = "AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ".(DAEMON_SLEEP_INTERVAL*2)." SECOND)"; + //} + if (DB_TYPE == "pgsql") { $update_limit_qpart = "AND ttrss_feeds.last_updated < NOW() - INTERVAL '".(DAEMON_SLEEP_INTERVAL*2)." seconds'"; + $update_limit_qpart = "AND (( + ttrss_feeds.update_interval = 0 + AND ttrss_feeds.last_updated < NOW() - INTERVAL ttrss_user_prefs.value || ' minutes' + ) OR ( + ttrss_feeds.update_interval > 0 + AND ttrss_feeds.last_updated < NOW() - INTERVAL ttrss_feeds.update_interval || ' minutes' + ))"; } else { - $update_limit_qpart = "AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ".(DAEMON_SLEEP_INTERVAL*2)." SECOND)"; + $update_limit_qpart = "AND (( + ttrss_feeds.update_interval = 0 + AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) + ) OR ( + ttrss_feeds.update_interval > 0 + AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) + ))"; } + if (DB_TYPE == "pgsql") { - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; - } else { - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; - } + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; + } else { + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; + } - $result = db_query($link, "SELECT feed_url,ttrss_feeds.id,owner_uid, - SUBSTRING(last_updated,1,19) AS last_updated, - update_interval + $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid, + SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated, + ttrss_feeds.update_interval FROM - ttrss_feeds,ttrss_users - WHERE - ttrss_users.id = owner_uid $login_thresh_qpart $update_limit_qpart - $updstart_thresh_qpart + ttrss_feeds, ttrss_users, ttrss_user_prefs + WHERE + ttrss_feeds.owner_uid = ttrss_users.id + AND ttrss_users.id = ttrss_user_prefs.owner_uid + AND ttrss_user_prefs.pref_name='DEFAULT_UPDATE_INTERVAL' + $login_thresh_qpart $update_limit_qpart + $updstart_thresh_qpart ORDER BY $random_qpart DESC LIMIT " . DAEMON_FEED_LIMIT); $user_prefs_cache = array(); @@ -242,49 +260,19 @@ while ($line = array_pop($feeds_to_update)) { - $upd_intl = $line["update_interval"]; - $user_id = $line["owner_uid"]; - - if (!$upd_intl || $upd_intl == 0) { - if (!$user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL']) { - $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id); - $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL'] = $upd_intl; - } else { - $upd_intl = $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL']; - } - } - - if ($upd_intl < 0) { - # print "Updates disabled.\n"; - continue; - } - _debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]); - // _debug(sprintf("\tLU: %d, INTL: %d, UID: %d) ", - // time() - strtotime($line["last_updated"]), $upd_intl*60, $user_id)); - - if (!$line["last_updated"] || - time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) { - - _debug("Updating..."); - - pcntl_alarm(300); + pcntl_alarm(300); + update_rss_feed($link, $line["feed_url"], $line["id"], true); + pcntl_alarm(0); - update_rss_feed($link, $line["feed_url"], $line["id"], true); - - pcntl_alarm(0); - - sleep(1); // prevent flood (FIXME make this an option?) - } else { - _debug("Update not needed."); - } + sleep(1); // prevent flood (FIXME make this an option?) } if (DAEMON_SENDS_DIGESTS) send_headlines_digests($link); _debug("Elapsed time: " . (time() - $start_timestamp) . " second(s)"); - + db_close($link); // We are in a fork. @@ -293,6 +281,10 @@ // We exit in order to avoid fork bombing. exit(0); } + + // We wait a little time before the next fork, in order to let the first fork + // mark the feeds it update : + sleep(1); } $last_checkpoint = time(); } diff --git a/update_daemon_loop.php b/update_daemon_loop.php index 1f7e9184e..08fad1b97 100644 --- a/update_daemon_loop.php +++ b/update_daemon_loop.php @@ -117,8 +117,21 @@ if (DB_TYPE == "pgsql") { $update_limit_qpart = "AND ttrss_feeds.last_updated < NOW() - INTERVAL '".(DAEMON_SLEEP_INTERVAL*2)." seconds'"; + $update_limit_qpart = "AND (( + ttrss_feeds.update_interval = 0 + AND ttrss_feeds.last_updated < NOW() - INTERVAL ttrss_user_prefs.value || ' minutes' + ) OR ( + ttrss_feeds.update_interval > 0 + AND ttrss_feeds.last_updated < NOW() - INTERVAL ttrss_feeds.update_interval || ' minutes' + ))"; } else { - $update_limit_qpart = "AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ".(DAEMON_SLEEP_INTERVAL*2)." SECOND)"; + $update_limit_qpart = "AND (( + ttrss_feeds.update_interval = 0 + AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) + ) OR ( + ttrss_feeds.update_interval > 0 + AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) + ))"; } if (DB_TYPE == "pgsql") { @@ -127,14 +140,17 @@ $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; } - $result = db_query($link, "SELECT feed_url,ttrss_feeds.id,owner_uid, - SUBSTRING(last_updated,1,19) AS last_updated, - update_interval + $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid, + SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated, + ttrss_feeds.update_interval FROM - ttrss_feeds,ttrss_users - WHERE - ttrss_users.id = owner_uid $login_thresh_qpart $update_limit_qpart - $updstart_thresh_qpart + ttrss_feeds, ttrss_users, ttrss_user_prefs + WHERE + ttrss_feeds.owner_uid = ttrss_users.id + AND ttrss_users.id = ttrss_user_prefs.owner_uid + AND ttrss_user_prefs.pref_name='DEFAULT_UPDATE_INTERVAL' + $login_thresh_qpart $update_limit_qpart + $updstart_thresh_qpart ORDER BY $random_qpart DESC LIMIT " . DAEMON_FEED_LIMIT); $user_prefs_cache = array(); @@ -143,43 +159,13 @@ while ($line = db_fetch_assoc($result)) { - $upd_intl = $line["update_interval"]; - $user_id = $line["owner_uid"]; - - if (!$upd_intl || $upd_intl == 0) { - if (!$user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL']) { - $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id); - $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL'] = $upd_intl; - } else { - $upd_intl = $user_prefs_cache[$user_id]['DEFAULT_UPDATE_INTERVAL']; - } - } - - if ($upd_intl < 0) { -# print "Updates disabled.\n"; - continue; - } - _debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]); -// _debug(sprintf("\tLU: %d, INTL: %d, UID: %d) ", -// time() - strtotime($line["last_updated"]), $upd_intl*60, $user_id)); - - if (!$line["last_updated"] || - time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) { + pcntl_alarm(300); + update_rss_feed($link, $line["feed_url"], $line["id"], true); + pcntl_alarm(0); - _debug("Updating..."); - - pcntl_alarm(300); - - update_rss_feed($link, $line["feed_url"], $line["id"], true); - - pcntl_alarm(0); - - sleep(1); // prevent flood (FIXME make this an option?) - } else { - _debug("Update not needed."); - } + sleep(1); // prevent flood (FIXME make this an option?) } if (DAEMON_SENDS_DIGESTS) send_headlines_digests($link); |