update_daemon improvements
This commit is contained in:
+20
-7
@@ -3,12 +3,10 @@
|
|||||||
// this daemon runs in the background and updates all feeds
|
// this daemon runs in the background and updates all feeds
|
||||||
// continuously
|
// continuously
|
||||||
|
|
||||||
define('SLEEP_INTERVAL', 10); // seconds
|
declare(ticks = 1);
|
||||||
|
|
||||||
// TODO: allow update scheduling from users
|
|
||||||
|
|
||||||
|
define('SLEEP_INTERVAL', 10); // seconds between update runs
|
||||||
define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
|
define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-daemon');
|
||||||
|
|
||||||
define('DISABLE_SESSIONS', true);
|
define('DISABLE_SESSIONS', true);
|
||||||
|
|
||||||
require_once "sanity_check.php";
|
require_once "sanity_check.php";
|
||||||
@@ -18,6 +16,20 @@
|
|||||||
require_once "functions.php";
|
require_once "functions.php";
|
||||||
require_once "magpierss/rss_fetch.inc";
|
require_once "magpierss/rss_fetch.inc";
|
||||||
|
|
||||||
|
function sigint_handler() {
|
||||||
|
unlink("update_daemon.lock");
|
||||||
|
die("Received SIGINT. Exiting.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
pcntl_signal(SIGINT, sigint_handler);
|
||||||
|
|
||||||
|
$lock_handle = make_lockfile("update_daemon.lock");
|
||||||
|
|
||||||
|
if (!$lock_handle) {
|
||||||
|
die("error: Can't create lockfile ($lock_filename). ".
|
||||||
|
"Maybe another daemon is already running.");
|
||||||
|
}
|
||||||
|
|
||||||
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||||
|
|
||||||
if (!$link) {
|
if (!$link) {
|
||||||
@@ -35,6 +47,7 @@
|
|||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
// FIXME: get all scheduled updates w/forced refetch
|
// FIXME: get all scheduled updates w/forced refetch
|
||||||
|
// Stub, until I figure out if it is really needed.
|
||||||
|
|
||||||
# $result = db_query($link, "SELECT * FROM ttrss_scheduled_updates ORDER BY id");
|
# $result = db_query($link, "SELECT * FROM ttrss_scheduled_updates ORDER BY id");
|
||||||
# while ($line = db_fetch_assoc($result)) {
|
# while ($line = db_fetch_assoc($result)) {
|
||||||
@@ -50,7 +63,7 @@
|
|||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
|
|
||||||
print "Checking feed: " . $line["feed_url"] . "\n";
|
print "Feed: " . $line["feed_url"] . ": ";
|
||||||
|
|
||||||
$upd_intl = $line["update_interval"];
|
$upd_intl = $line["update_interval"];
|
||||||
|
|
||||||
@@ -72,9 +85,9 @@
|
|||||||
time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
|
time() - strtotime($line["last_updated"]) > ($upd_intl * 60)) {
|
||||||
|
|
||||||
print "Updating...\n";
|
print "Updating...\n";
|
||||||
|
|
||||||
update_rss_feed($link, $line["feed_url"], $line["id"], true);
|
update_rss_feed($link, $line["feed_url"], $line["id"], true);
|
||||||
|
} else {
|
||||||
|
print "Update not needed.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user