How do I run events before a worker is created and when it is destroyed?

25 Views Asked by At

I want to create a new puppeteer browser when a Laravel Worker gets created.

Right now, my Horizon config allows for a minimum of 2 and a maximum of 10 workers running. As demand increases and workers are created, I'd like to create a new browser for Puppeteer. When a worker is removed, it can close that browser.

Are there any Laravel events that would work for this? Or am I coming at this the wrong way?

I looked into puppeteer-cluster, but that's another queue to interact with when I already have one with Laravel. And the puppeteer-pool is out of date.

1

There are 1 best solutions below

0
Kevin Bui On

This is the current list of built-in events for queuing in Laravel 11:

enter image description here

Looping sounds like the right event, you can give that a try.

If not, you can create a new event named QueueStarting and create a PR to the framework.