/**
     * Main method: infinite method that monitors queued objects, and starts
     * the publishinbg processes if allowed
     *
     * @return void
     */
    public function run()
    {
        // use DB exceptions so that errors can be fully handled
        eZDB::setErrorHandling( eZDB::ERROR_HANDLING_EXCEPTIONS );

        $this->cleanupDeadProcesses();

        while ( $this->canProcess )
        {
            try {
                /**
                 * @var ezpContentPublishingProcess
                 */
                $publishingItem = call_user_func( array( $this->queueReader, 'next' ) );
                if ( $publishingItem !== false )
                {
                    if ( !$this->isSlotAvailable() )
                    {
                        $this->out->write( "No slot is available", 'async.log' );
                        sleep ( 1 );
                        continue;
                    }
                    else
                    {
                        $this->out->write( "Processing item #" . $publishingItem->attribute( 'ezcontentobject_version_id' ), 'async.log' );
                        $pid = $publishingItem->publish();
                        pcntl_signal( SIGINT, $this->signalHandler );
                        $this->currentJobs[$pid] = $publishingItem;

                        // In the event that a signal for this pid was caught before we get here, it will be in our
                        // signalQueue array
                        // Process it now as if we'd just received the signal
                        if( isset( $this->signalQueue[$pid] ) )
                        {
                            $this->out->write( "found $pid in the signal queue, processing it now" );
                            $this->childSignalHandler( SIGCHLD, $pid, $this->signalQueue[$pid] );
                            unset( $this->signalQueue[$pid] );
                        }
                    }
                }
                else
                {
                    sleep( $this->sleepInterval );
                }
            } catch ( eZDBException $e ) {
                $this->out->write( "Database error #" . $e->getCode() . ": " . $e->getMessage() );
                // force the DB connection closed so that it is recreated
                try {
                    $db = eZDB::instance();
                    $db->close();
                    $db = null;
                    eZDB::setInstance( null );
                } catch( eZDBException $e ) {
                    // Do nothing, this will be retried until the DB is back up
                }
                sleep( 1 );
            }
        }
    }