Webador / SlmQueue

Laminas / Mezzio module that integrates with various queue management systems.
Other
138 stars 57 forks source link

Raise an exception but not noticed #256

Closed arstom closed 1 year ago

arstom commented 1 year ago

Hi, Can you please help me to rais an exception? I'm not sure what I'm doing wrong but I cannot force my queue to raise an exception.

I've registered EVENT_PROCESS_JOB as event and trying to force an exception by execute() method and return value unequal 1. But I cannot see any exception raised on my cli.

What am I doing wrong?


class ApiCallerJob extends AbstractJob
{
    public function __construct(ContainerInterface $container)
    {
        $this->event = new EventManager();
        $this->event->attach(Event\WorkerEventInterface::EVENT_PROCESS_JOB, function ($e) {
                    echo 'Event ' . Event\WorkerEventInterface::EVENT_PROCESS_JOB . PHP_EOL;
            $result = $e->getResult();
            $job = $e->getJob();
            if (Event\ProcessJobEvent::JOB_STATUS_FAILURE === $result) {
            }
            echo $job->getId() . PHP_EOL;
            echo get_class($job) .PHP_EOL;
        });
    }

    public function execute(): int
    {
       ...
       throw new \SlmQueue\Exception\RuntimeException('Test Exception');
       ...
       return Event\ProcessJobEvent::JOB_STATUS_FAILURE_RECOVERABLE;
    }
}
`
roelvanduijnhoven commented 1 year ago

Hey @arstom :wave:

This part of the job looks correct:

    public function execute(): int
    {
       ...
       throw new \SlmQueue\Exception\RuntimeException('Test Exception');
       ...
       return Event\ProcessJobEvent::JOB_STATUS_FAILURE_RECOVERABLE;
    }

But .. really not sure what you are doing in your controller! I think you can safely remove all that code.

If you throw an exception from the excecute method, the job will receive status 4, and you can find that entry in your queueing system. Specifics will depend on your adapter. What adapter do you use? (for example in SlmQueueDoctrine, you will still find the job with status 4 in the database after a crash, with the stack-trace)

arstom commented 1 year ago

Now, I tried to use

throw new \SlmQueueDoctrine\Job\Exception\ReleasableException(["delay" => 300]);

and this was successful. Thanks

roelvanduijnhoven commented 1 year ago

Great!

So that way the job will retry itself. So if you want that: great!

If you throw any other exception, the job will simply remain in the failed queue. And you will have to restart manually :).

arstom commented 1 year ago

In addition, I have set following settings which helped me to receive "normal" runtime exceptions, too. :-)


'buried_lifetime' => 3600,
'deleted_lifetime' => 7 * 24 * 3600
`