diff --git a/bin/php/ezasynchronouspublisher.php b/bin/php/ezasynchronouspublisher.php index 5ad05e69c6b..88e5d5b749d 100755 --- a/bin/php/ezasynchronouspublisher.php +++ b/bin/php/ezasynchronouspublisher.php @@ -35,27 +35,16 @@ $options = $script->getOptions( // options definition - "[n|daemon][p:|pid-file:][cleanup-interval:]", + "[n|daemon][p:|pid-file:]", // arguments definition "", // options documentation array( 'daemon' => 'Run in the background', - 'pid-file' => 'PID file', - 'cleanup-interval' => 'Number of seconds between each db table cleanup. Default value is 43200 (12 hours)' ) ); + 'pid-file' => 'PID file' ) ); $sys = eZSys::instance(); $script->initialize(); -$cleanup = 0; -if ( isset( $options['cleanup-interval'] ) ) -{ - $cleanup = $options['cleanup-interval']; - if ( !is_int( $cleanup ) || $cleanup < 1 ) - { - $script->shutdown( 3, "Invalid value for cleanup-interval:'$cleanup'" ); - } -} - if ( isset( $options['pid-file'] ) ) { $pidFile = $options['pid-file']; @@ -203,7 +192,6 @@ $processor = ezpContentPublishingQueueProcessor::instance(); $processor->setOutput( $output ); $processor->setSignalHandler( $daemonSignalHandler ); -$processor->setCleanupInterval( $cleanup ); $processor->run(); eZScript::instance()->shutdown( 0 ); diff --git a/kernel/private/classes/ezpcontentpublishingqueueprocessor.php b/kernel/private/classes/ezpcontentpublishingqueueprocessor.php index 98781ef6641..6ce5c806e8e 100644 --- a/kernel/private/classes/ezpcontentpublishingqueueprocessor.php +++ b/kernel/private/classes/ezpcontentpublishingqueueprocessor.php @@ -30,6 +30,8 @@ public function __construct() // initiates timer for the DB cleanup process $this->cleanupLastTime = time(); + $this->cleanupInterval = $this->contentINI->variable( 'PublishingSettings', 'AsynchronousCleanupInterval' ); + $this->cleanupAgeLimit = $this->contentINI->variable( 'PublishingSettings', 'AsynchronousCleanupAgeLimit' ); // Queue reader handler $this->queueReader = $this->contentINI->variable( 'PublishingSettings', 'AsynchronousPublishingQueueReader' ); @@ -154,8 +156,8 @@ private function cleanupDeadProcesses() } /** - * Removes FINISHED processes rows from the db, older than one week, all in one db call - * method self-manages the removal, based on the defined treshhold + * Removes FINISHED processes rows from the db (in one db call) + * method self-manages the removal, based on the defined cleanupInterval and cleanupAgeLimit * * @return void */ @@ -176,9 +178,9 @@ private function cleanupFinishedProcesses() eZDebug::writeNotice( "ASYNC:: removing processes entries marked as STATUS_FINISHED in database."); $db = eZDB::instance(); eZDB::setInstance( null ); - $lastWeek = time() - (7 * 24 * 60 * 60); + $deleteBefore = time() - $this->cleanupAgeLimit; $processTable = ezpContentPublishingProcess::definition()['name']; - $db->query( "DELETE from ". $processTable. " WHERE status =". ezpContentPublishingProcess::STATUS_FINISHED. " AND finished < ". $lastWeek ); + $db->query( "DELETE from ". $processTable. " WHERE status =". ezpContentPublishingProcess::STATUS_FINISHED. " AND finished < ". $deleteBefore ); $this->cleanupLastTime = time(); } catch( eZDBException $e ) @@ -302,19 +304,6 @@ private function getNextItem() return call_user_func( array( $this->queueReader, 'next' ) ); } - /** - * Sets the cleanup variables - * @param int $interval - * @param \ - */ - public function setCleanupInterval( $interval ) - { - if ( $interval > 0 ) - { - $this->cleanupInterval = $interval; - } - } - /** * @var eZINI */ @@ -368,5 +357,12 @@ public function setCleanupInterval( $interval ) * @var int */ private $cleanupInterval = 43200; + + /** + * All finished processes after this age limit will be cleaned up. + * Default value is a week (in seconds) + * @var int + */ + private $cleanupAgeLimit = 604800; } ?> diff --git a/settings/content.ini b/settings/content.ini index c9a9ef5c5ca..61cc0220857 100755 --- a/settings/content.ini +++ b/settings/content.ini @@ -511,6 +511,14 @@ AsynchronousPublishingQueueReader=ezpContentPublishingQueue # default: 1 AsynchronousPollingInterval=1 +# How frequent the daemon cleans the queue (sleep in seconds) +# default: 43200 (12 hours) +AsynchronousCleanupInterval=43200 + +# How old processes need to be in order to be cleaned (in seconds) +# default: 604800 (a week) +AsynchronousCleanupAgeLimit=604800 + [TestingSettings] # Enable or disable multivariate testing feature MultivariateTesting=disabled