/** * 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 */ private function cleanupFinishedProcesses() { if ( time() < ( $this->cleanupLastTime + $this->cleanupInterval ) ) { return; } $processes = count( ezpContentPublishingProcess::fetchProcesses( ezpContentPublishingProcess::STATUS_FINISHED ) ); if ( $processes > 0 ) { //Remove all objects at once // this is required as the MySQL connection might be closed anytime by a fork try { eZDebug::writeNotice( "ASYNC:: removing processes entries marked as STATUS_FINISHED in database."); $db = eZDB::instance(); eZDB::setInstance( null ); $deleteBefore = time() - $this->cleanupAgeLimit; $definition = ezpContentPublishingProcess::definition(); $processTable = $definition['name']; $db->query( "DELETE from ". $processTable. " WHERE status =". ezpContentPublishingProcess::STATUS_FINISHED. " AND finished < ". $deleteBefore ); $this->cleanupLastTime = time(); } catch( eZDBException $e ) { // Do nothing, this will be retried until the DB is back up } } }
/** * Returns the next processable item * @return ezpContentPublishingProcess The next object to process, or false if none is available */ public static function next() { $queuedProcess = eZPersistentObject::fetchObjectList( ezpContentPublishingProcess::definition(), null, array( 'status' => ezpContentPublishingProcess::STATUS_PENDING ), array( 'created' => 'desc' ), array( 'offset' => 0, 'length' => 1 ) ); if ( count( $queuedProcess ) == 0 ) return false; else return $queuedProcess[0]; }
/** * Make sure that eZPersistentObject can build instances of this class * @return array */ public static function definition() { $definition = parent::definition(); $definition['class_name'] = 'eZPerfLoggerContentPublishingProcess'; return $definition; }