Skip to content

Commit

Permalink
Merge pull request #1077 from ezsystems/ezp-23312-added_ini_conf_asyn…
Browse files Browse the repository at this point in the history
…c_publish

Fix EZP-23312: Async pub: old processes are filling up the database
  • Loading branch information
yannickroger committed Sep 23, 2014
2 parents cdd7c47 + 4de6a77 commit c101226
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
16 changes: 2 additions & 14 deletions bin/php/ezasynchronouspublisher.php
Expand Up @@ -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'];
Expand Down Expand Up @@ -203,7 +192,6 @@
$processor = ezpContentPublishingQueueProcessor::instance();
$processor->setOutput( $output );
$processor->setSignalHandler( $daemonSignalHandler );
$processor->setCleanupInterval( $cleanup );
$processor->run();

eZScript::instance()->shutdown( 0 );
Expand Down
30 changes: 13 additions & 17 deletions kernel/private/classes/ezpcontentpublishingqueueprocessor.php
Expand Up @@ -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' );
Expand Down Expand Up @@ -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
*/
Expand All @@ -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 )
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
?>
8 changes: 8 additions & 0 deletions settings/content.ini
Expand Up @@ -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
Expand Down

0 comments on commit c101226

Please sign in to comment.