The queue is still block worker to process next job.
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
Does https://github.com/barryvdh/laravel-async-queue/commit/7ed454f0050affa034e5d9f8743009aac76975f3 fix this (on 0.3.x@dev)? Are you using windows/linux/hhvm?
Haven't try it yet, Will try it today. Thanks for the update.
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;
}
}
}
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.
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?
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.