]> git.wh0rd.org - tt-rss.git/blobdiff - update_daemon2.php
typos: "interval" has a value, option->options
[tt-rss.git] / update_daemon2.php
index 450b9339dc14784e0e49ae381241b7de0c7995b3..2fbdd8b8cde7db3b68be98c91ce6fe812d967b93 100755 (executable)
 
        $longopts = array("log:",
                        "tasks:",
-                       "interval",
+                       "interval:",
                        "quiet",
                        "help");
 
 
        if (isset($options["tasks"])) {
                _debug("Set to spawn " . $options["tasks"] . " children.");
-               $max_jobs = $option["tasks"];
+               $max_jobs = $options["tasks"];
        } else {
                $max_jobs = MAX_JOBS;
        }
 
        if (isset($options["interval"])) {
                _debug("Spawn interval: " . $options["interval"] . " seconds.");
-               $spawn_interval = $option["interval"];
+               $spawn_interval = $options["interval"];
        } else {
                $spawn_interval = SPAWN_INTERVAL;
        }
        // It is unnecessary to start the fork loop if database is not ok.
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
 
-       if (!init_connection($link)) return;
+       if (!init_connection($link)) die("Can't initialize db connection.\n");
+
+       $schema_version = get_schema_version($link);
 
        db_close($link);
 
 
                if ($last_checkpoint + $spawn_interval < time()) {
 
+                       /* Check if schema version changed */
+
+                       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+                       if (!init_connection($link)) die("Can't initialize db connection.\n");
+                       $test_schema_version = get_schema_version($link);
+                       db_close($link);
+
+                       if ($test_schema_version != $schema_version) {
+                               _debug("Expected schema version: $schema_version, got: $test_schema_version");
+                               _debug("Schema version changed while we were running, bailing out");
+                               exit(100);
+                       }
+
                        check_ctimes();
                        reap_children();
 
 
                                        $nf = 0;
 
-                                       _debug("Waiting before update..");
-                                       sleep(rand(5,15));
+                                       _debug("Waiting before update [$j]..");
+                                       sleep($j*5);
                                        $nf = update_daemon_common($link);
 
                                        if (rand(0,100) > 50) {