laravel-async-queue icon indicating copy to clipboard operation
laravel-async-queue copied to clipboard

The queue is still block worker to process next job.

Open Armxy opened this issue 11 years ago • 6 comments

My issue is I've use async queue as an internal queue. I got my beanstalkd as a default and grab the external queue from it. In handler, I then re-assign to async queue so it unlock the worker from grabing another queue from beanstalkd.

Worker eventually timed out. even the handler is finished working.

Here's my controller code.

<?php

class QueueController extends BaseController {

    public function fire($job, $data)
    {
            \Queue::connection('async')
                ->push(function($job) use ($object) {
                    $object->doSomething(); // This is time consuming process.
                    $job->delete();
                });

        $job->delete();
    }

Here's my worker command.

php artisan queue:listen --queue=beanstalkd

Armxy avatar Oct 31 '14 09:10 Armxy

Does https://github.com/barryvdh/laravel-async-queue/commit/7ed454f0050affa034e5d9f8743009aac76975f3 fix this (on 0.3.x@dev)? Are you using windows/linux/hhvm?

barryvdh avatar Nov 19 '14 13:11 barryvdh

Haven't try it yet, Will try it today. Thanks for the update.

Armxy avatar Nov 20 '14 01:11 Armxy

I'm having a similar problem. The code hangs on each one of these cases. The lines with $reference->... are time consuming tasks.

foreach ($rotinas as $rotina) 
{
    $cron = CronExpression::factory($rotina->expressao_cron);

    if($rotina->executando == 0 && $cron->isDue())
    {
        set_time_limit(30000);

        $rotina->data_hora_ultima_execucao = Carbon::now();
        $rotina->executando = 1;
        $rotina->save();

        try
        {
            switch($rotina->id)
            {
                case 4:
                {
                    $reference = $this;

                    \Queue::push(function($job) use ($reference, $rotina)
                    {
                        \Log::info('ROTINA_EXECUTAR - ' . $rotina->nome);
                        $reference->calcularConsumoMensal($rotina);
                        $job->delete();
                    });

                    break;
                }

                case 5:
                {
                    $reference = $this;

                    \Queue::push(function($job) use ($reference, $rotina)
                    {
                        \Log::info('ROTINA_EXECUTAR - ' . $rotina->nome);
                        $reference->calcularConsumo24Horas($rotina);
                        $job->delete();
                    });

                    break;
                }

                case 7:
                {
                    $reference = $this;

                    \Queue::push(function($job) use ($reference, $rotina)
                    {
                        \Log::info('ROTINA_EXECUTAR - ' . $rotina->nome);
                        $reference->calcularConsumo3Dias($rotina);
                        $job->delete();
                    });

                    break;
                }
            }

            $rotina->executando = 0;
            $rotina->save();

            \Log::info('ROTINA_EXECUTAR - FIM');
        }

        catch(\Exception $e)
        {
            $rotina->executando = 0;
            $rotina->save();

            \Log::info('ROTINA_EXECUTAR - ERRO_FIM');

            throw $e;
        }
    }
}

SDantas avatar Jan 15 '15 13:01 SDantas

As far as I understand, first $reference->... Will be execute but after that won't. If so, i guess that's because by the time it try to run another job, worker is still busy doing previous one.

I'm end up write my own fork from this lib which really queue up the job using db, and its required a worker to grab the job. I havn't test if it work as expected with closure job or not, welcome to try tho.

Armxy avatar Jan 15 '15 13:01 Armxy

Actually I just tried your fork, and it works as expected (not holding the code when queueing), but only with the php artisan queue:listen running. Is that how it is supposed to work?

SDantas avatar Jan 15 '15 13:01 SDantas

Yes, and you could always run worker from your code using exec() after this main loop. Invoke it again after $reference->... is done and you delete the job to grab another. And it should finish all the queue.

Armxy avatar Jan 15 '15 13:01 Armxy