Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EZP-23312: Async pub: old processes are filling up the database #1077

Merged
merged 1 commit into from
Sep 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions bin/php/ezasynchronouspublisher.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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