]> git.wh0rd.org Git - tt-rss.git/commitdiff
check update daemon timestamp
authorAndrew Dolgov <fox@bah.spb.su>
Mon, 16 Jul 2007 13:05:29 +0000 (14:05 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Mon, 16 Jul 2007 13:05:29 +0000 (14:05 +0100)
functions.php
modules/popup-dialog.php
tt-rss.js

index 1aa6f32b45774df6803f09297f9c688e21b319e7..6376a282c8b3cd2393e02aaf483adec96e9bde67 100644 (file)
        function make_stampfile($filename) {
                $fp = fopen($filename, "w");
 
-               if ($fp) {
+               if (flock($fp, LOCK_EX | LOCK_NB)) {
                        fwrite($fp, time() . "\n");
+                       flock($fp, LOCK_UN);
                        fclose($fp);
                        return true;
                } else {
                }
        }
 
+       function read_stampfile($filename) {
+
+               error_reporting(0);
+               $fp = fopen($filename, "r");
+               error_reporting (DEFAULT_ERROR_LEVEL);
+
+               if (flock($fp, LOCK_EX)) {
+                       $stamp = fgets($fp);
+                       flock($fp, LOCK_UN);
+                       fclose($fp);
+                       return $stamp;
+               } else {
+                       return false;
+               }
+       }
 
        function sql_random_function() {
                if (DB_TYPE == "mysql") {
                if (ENABLE_UPDATE_DAEMON) {
                        print "<param key=\"daemon_is_running\" value=\"".
                                sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>";
+
+                       if ($_SESSION["daemon_stamp_check"] + 0 < time()) {
+
+                               $stamp = (int)read_stampfile("update_daemon.stamp");
+
+                               if ($stamp) {
+                                       if ($stamp + 86400*3 < time()) {
+                                               print "<param key=\"daemon_stamp_ok\" value=\"0\"/>";
+                                       } else {
+                                               print "<param key=\"daemon_stamp_ok\" value=\"1\"/>";
+                                       }
+
+                                       $stamp_fmt = date("Y.m.d, G:i", $stamp);
+
+                                       print "<param key=\"daemon_stamp\" value=\"$stamp_fmt\"/>";
+                               }
+
+                               $_SESSION["daemon_stamp_check"] = time();
+                       }
                }
+
                if (CHECK_FOR_NEW_VERSION && $_SESSION["access_level"] >= 10) {
                        
                        if ($_SESSION["last_version_check"] + 600 < time()) {
index ef9f1362919e8f66247ad95f3aa9ee61f02f3c44..562093d9d6d5788ac2deb6b5928b5ef3c1d8fa16 100644 (file)
 
                        }
 
+                       if ($param == 3) {
+                               print __("TT-RSS has detected that update daemon is taking too long to
+                                       perform a feed update. This could indicate a problem like crash
+                                       or a hang. Please check the daemon process or contact instance
+                                       owner.");
+                       }
+
                        print "</div>";
 
                        print "<div align='center'>";
index 96418db9e6f2a454e2e8f22b0c64675e659977b2..10f1a7ef321a3a138108d63fc026464b4c129816 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -604,9 +604,19 @@ function parse_runtime_info(elem) {
                        }
                }
 
+               var error_flag;
+
                if (k == "daemon_is_running" && v != 1) {
-                       notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>");
-               } else {
+                       notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
+                       error_flag = true;
+               }
+
+               if (k == "daemon_stamp_ok" && v != 1) {
+                       notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
+                       error_flag = true;
+               }
+
+               if (!error_flag) {
                        notify('');
                }