0

I'm trying to run a job queue to create a PDF file using SlmQueueBeanstalkd and DOMPDFModule in ZF".

Here's what I'm doing in my controller:

public function reporteAction()
{

    $job = new TareaReporte();
    $queueManager = $this->serviceLocator->get('SlmQueue\Queue\QueuePluginManager');
    $queue = $queueManager->get('myQueue');
    $queue->push($job);
    
    ...

}

This is the job:

namespace Application\Job;

use SlmQueue\Job\AbstractJob;
use SlmQueue\Queue\QueueAwareInterface;
use SlmQueue\Queue\QueueInterface;
use DOMPDFModule\View\Model\PdfModel;

class TareaReporte extends AbstractJob implements QueueAwareInterface
{

    protected $queue;

    public function getQueue()
    {
        return $this->queue;
    }

    public function setQueue(QueueInterface $queue)
    {
        $this->queue = $queue;
    }

    public function execute()
    {
        $sm = $this->getQueue()->getJobPluginManager()->getServiceLocator();
        $empresaTable = $sm->get('Application\Model\EmpresaTable');
        $registros = $empresaTable->listadoCompleto();
        $model = new PdfModel(array('registros' => $registros));
        $model->setOption('paperSize', 'letter');
        $model->setOption('paperOrientation', 'portrait');
        $model->setTemplate('empresa/reporte-pdf');

        $output = $sm->get('viewPdfrenderer')->render($model);

        $filename = "/path/to/pdf/file.pdf";
        file_put_contents($filename, $output);
    }
}

The first time you run it, the file is created and the work is successful, however, if you run a second time, the task is buried and the file is not created.

It seems that stays in an endless cycle when trying to render the model a second time.

Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

0

I've had a similar issue and it turned out it was because of the way ZendPdf\PdfDocument reuses it's object factory. Are you using ZendPdf\PdfDocument?

You might need to correctly close factory.

class MyDocument extends PdfDocument
{
    public function __destruct()
    {
        $this->_objFactory->close();
    }
}

Try to add this or something similar to the PdfDocument class...

update : it seem you are not using PdfDocument, however I suspect this is the issue is the same. Are you able to regenerate a second PDF in a normal http request? It is your job to make sure the environment is equal on each run. If you are unable to overcome this problem a short-term quick solution would be to set max_runs configuration for SlmQueue to 1. That way the worker is stopped after each job and this reset to a vanilla state...

bas
  • 628
  • 9
  • 22
  • thanks for taking the time to respond. Your reply has been helpful. I have not been able to locate what is causing the problem. For now, I opted for the quick fix set max_runs SlmQueue to 1. Stopping the worker after each job creates pdf document correctly. – Carlos Álvarez Feb 17 '14 at 13:54