Browse Source

Mutex pour actualize_script

Nouveau fichier temporaire ./data/actualize.lock.txt
Alexandre Alapetite 12 years ago
parent
commit
3b23ca881c
4 changed files with 21 additions and 4 deletions
  1. 1 1
      app/Controllers/indexController.php
  2. 1 1
      app/FreshRSS.php
  3. 18 2
      app/actualize_script.php
  4. 1 0
      data/.gitignore

+ 1 - 1
app/Controllers/indexController.php

@@ -133,7 +133,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 
 			// Si on a récupéré aucun article "non lus"
 			// on essaye de récupérer tous les articles
-			if ($state === 'not_read' && empty($entries)) {	//TODO: Remove in v0.8
+			if ($state === 'not_read' && empty($entries)) {
 				Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG);
 				$this->view->state = 'all';
 				$entries = $this->entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter, $date_min, $keepHistoryDefault);

+ 1 - 1
app/FreshRSS.php

@@ -6,7 +6,7 @@ class FreshRSS extends Minz_FrontController {
 		}
 		$this->accessControl(Minz_Session::param('currentUser', ''));
 		$this->loadParamsView();
-		$this->loadStylesAndScripts();
+		$this->loadStylesAndScripts();	//TODO: Do not load that when not needed, e.g. some Ajax requests
 		$this->loadNotifications();
 	}
 

+ 18 - 2
app/actualize_script.php

@@ -1,7 +1,19 @@
 <?php
 require(dirname(__FILE__) . '/../constants.php');
 
-//TODO: check if already running
+//<Mutex>
+$lock = DATA_PATH . '/actualize.lock.txt';
+if (file_exists($lock) && ((time() - @filemtime($lock)) > 3600)) {
+	@unlink($lock);
+}
+if (($handle = @fopen($lock, 'x')) === false) {
+	syslog(LOG_INFO, 'FreshRSS actualize already running?');
+	return;
+}
+register_shutdown_function('unlink', $lock);
+//Could use http://php.net/function.pcntl-signal.php to catch interruptions
+@fclose($handle);
+//</Mutex>
 
 require(LIB_PATH . '/lib_rss.php');	//Includes class autoloader
 
@@ -10,8 +22,12 @@ ob_implicit_flush(false);
 ob_start();
 echo 'Results: ', "\n";	//Buffered
 
+Minz_Configuration::init();
+
 $users = listUsers();
-shuffle($users);
+shuffle($users);	//Process users in random order
+array_unshift($users, Minz_Configuration::defaultUser());	//But always start with admin
+$users = array_unique($users);
 
 foreach ($users as $myUser) {
 	syslog(LOG_INFO, 'FreshRSS actualize ' . $myUser);

+ 1 - 0
data/.gitignore

@@ -5,3 +5,4 @@ config.php
 touch.txt
 no-cache.txt
 *.bak.php
+*.lock.txt