3

I am using Laravel Queues and I am using IronMQ for it. But I have little bit confusion about how this process.

I have set my default connection in queue.php as 'default' => 'iron' and also set iron settings in same file.

Now I use

 $this->dispatch(new createEvents($data, $user));

while createEvents class is a job class created as explained in Laravel tutorial. Now when following code is executed

$this->dispatch(new createEvents($data, $user));

It successfully creates a queue in my ironmQ account under project.

Now here is my confusion starts. I have queued some task to that queue but now how will I run that queue? How will I run the task that is queued? Do I need to create some extra code for it or Do I need to do some settings for it. Please guide

Awais Qarni
  • 14,876
  • 22
  • 72
  • 134

3 Answers3

3

You don't need to go to your server and run this command by hand, you need to have process that will keep running, and perform those jobs.

I would recomment "supervisord" http://supervisord.org/

This programs is for launching a script and keep it running, even if it fails, it will relaunch it(until certain amount of failures of course)

After you install it, you should probably create this supervisor task file:

[program:queue]
command=php artisan queue:listen --tries=3 --env=your_environment
directory=/path/to/laravel
stdout_logfile=/path/to/laravel/app/storage/logs/supervisord.log
redirect_stderr=true
autostart=true
autorestart=true
Tzook Bar Noy
  • 10,111
  • 12
  • 45
  • 75
1

You can do php artisan queue:listen it will start all listed queue or if you specify the queue name php artisan queue:listen queue_name

Don't forget to run php artisan queue:failed-table. This will make failed_jobs table in your database.

So if anything goes wrong when the queue run it will save failed queue to the database.

If you want the failed queue to get insert the database add this when run listen:

php artisan queue:listen connection-name --tries=3

to run the failed queue php artisan queue:retry all

Hope i answer your question.

ssuhat
  • 6,243
  • 14
  • 50
  • 97
  • How can I automate this process? Is there any way where I don't need to run that command in my CLI?\ – Awais Qarni Dec 31 '15 at 09:32
  • As Far as iknow it need using `queue:listen` – ssuhat Dec 31 '15 at 09:33
  • But `$this->dispatch(new createEvents($data, $user));` not saving any thing in my local database jobs table. That is always empty – Awais Qarni Dec 31 '15 at 09:34
  • I never use `ironmq`. as i know if you are not using database driver, it won't save to your database. that means ironmq handle it. For example i use `beanstalkd` to handle the queue it never save anything to database except `failed_jobs` – ssuhat Dec 31 '15 at 09:36
0

Once your job is in the queue, and according to your question it is, you have two simple options:

  1. Run one or more queue listeners on the same/different servers (using supervisor is recommended in Laravel documentation, see sample configuration)

  2. Run queue worker manually or automatically, on regular basis (crontab)

    php artisan queue:work iron

This command will fetch one job from the queue and process it. You launch it again – it fetches one more, and so on.

If you don't do extra processing and your queue driver is not 'sync' – your job will never see the day light.

My advice – launch queue workers manually on your development/test machine, and use supervisor on production server.

If your project is small and it doesn't require great scalability, you may want to simply switch to 'sync' driver (jobs will be processed immediately). There is no need to make the infrastructure more complicated, unless there is real necessity!

Denis Mysenko
  • 5,667
  • 19
  • 30