Brewless Brewless Docs

Running your application

Queues and schedule

How queue workers and scheduled tasks run in an environment, and what to do when a job fails.

On this page

Queue workers and the scheduler run in your own Scaleway project, next to the web container. After your first deploy they show up on the page of the environment.

Queues

The Queues tab lists the queues of the environment and their workers. Workers move to a new release together with the web container: both roll out at the same time, after the release commands ran.

Where the jobs wait is chosen when the environment is set up: in a queue at Scaleway Queues, which is the default, in its database, or nowhere, in which case a job runs where it is dispatched. See A queue. The worker is the same in each case.

By default the worker works the default queue of your application. Name the queues in your brewless.yml and the next deploy has the worker work those, the first first:

brewless.yml
environments:
  production:
    worker:
      queues: [default, mail]

This needs brewless/laravel 0.3 or later. Taking queues out of the file again keeps what the worker works; write [default] to go back.

An event that implements ShouldBroadcast is a job as well: the worker sends it on to the realtime server once it runs. Use ShouldBroadcastNow to send it during the request instead.

If a worker gives no sign of life for more than three minutes, the console says so. Check the trigger and the worker container in your Scaleway console.

Schedule

The Schedule tab shows when the scheduler last ran and when your provider calls it next. Below that, every task of your application's schedule with its command and when it runs, at the times your application sets them and in its own time zone. Under that, the moments your provider calls the worker, shown in your own time zone: a task in a time zone with summer time gets two of them, one for winter and one for summer (see How the worker is called). Everything on the tab is read from the worker when you open it; Brewless keeps none of it.

Failed jobs

Failed jobs can be put back on the queue from the console. The next run of the worker picks them up.

Note

Why a job failed is in your application's own failed_jobs table. Brewless does not read it: an error can quote the data it failed on.

An environment without a database keeps no failed jobs. Laravel keeps them in a table, and where no database is named it looks for that table in a SQLite file, which a container without a database does not have. The variables Brewless writes for such an environment therefore set QUEUE_FAILED_DRIVER=null; with a database they set QUEUE_FAILED_DRIVER=database-uuids, Laravel's own default. A database you add later takes the value over when it still says what Brewless set; a value you set yourself stays. brewless/laravel 1.7.1 and later does the same for an environment whose variables do not name it: where the failed jobs would be in a SQLite file that is not there, it keeps none.

How the worker is called

Nothing stays running on a serverless container: something has to call the worker. How depends on where the jobs wait.

Jobs in a queue at Scaleway Queues. The queue calls the worker as soon as a job is put on it, so a job runs right away: a sign-in code by mail, a file to process. Crons call the scheduler only at the moments your schedule has work. A task that runs every fifteen minutes gets a cron every fifteen minutes; one that runs at 02:10 gets one at 02:10. Nothing calls the worker in between, so it, and a serverless database, can sleep.

This needs brewless/laravel 0.4 or later, or for Laravel for Rust the brewless-laravel crate 0.3 with its sqs feature, or for Laravel for Go the module github.com/brewless/laravel-go: every job your application queues is then signed with the secret of its machine entrance, and the worker only runs a job whose signature holds. The worker runs a job the way queue:work does, with its tries, its backoff, its failed() and the failed jobs table. A job is given a few minutes before its queue would deliver it again: three, or the worker's timeout from brewless.yml plus half a minute when that is longer. Give a worker that runs long jobs a timeout above the longest job.

The moments come from your schedule itself, read from the worker on every deploy. Scaleway's crons run in UTC. A task in another time zone that is a whole number of hours from UTC, such as Europe/Amsterdam, keeps its minute, and its hours are moved to UTC by the winter and by the summer offset: ->dailyAt('07:00')->timezone('Europe/Amsterdam') calls the scheduler at 05:00 and 06:00 UTC (0 5 * * * and 0 6 * * *), and Laravel decides in that time zone which of the two is the moment. A task every hour, or every few hours, keeps only its minute (5 * * * *), and other tasks at that minute need no cron of their own. A task in a time zone with half hours, or written in a way a cron cannot copy, has the scheduler called every minute instead, which never misses one.

Jobs in the database. A trigger calls the worker every minute for one tick of the schedule, and then the queue, because the jobs in the database have to be looked for. The worker, and a serverless database, never get to sleep: Scaleway bills them around the clock. That is why brewless init and the console choose Scaleway Queues unless you choose otherwise, and why brewless plan says so next to queue: database. Choose the database only when you are sure you need it.

Nothing to call it for. An environment with scheduler: false whose jobs wait nowhere — QUEUE_CONNECTION=sync, as an environment set up without a queue gets — has nothing for the worker to be called about. A deploy takes the cron away as well, so nothing calls the worker at all and it sleeps until you call it yourself. The container stays: it costs nothing while it is scaled to zero, and brewless command runs in it. Set a QUEUE_CONNECTION that keeps jobs somewhere and the next deploy puts the cron back, for the queue alone.

Tip

A container sleeps after 15 minutes without a call. Tasks that run at the same minute of the hour, such as hourlyAt(5) and dailyAt('03:05'), share one wake-up; tasks spread over the hour each keep the worker awake a while longer.

Schedule

scheduler: false in your brewless.yml leaves the schedule out from the next deploy on; the queue is still worked. With no queue to work either, nothing calls the worker any more: see Nothing to call it for. scheduler: true puts the schedule back; leaving the key out keeps what stands.

The Schedule tab lists when the worker is called for the schedule: the crons at Scaleway. A task you add to your schedule gets its moment with the next deploy.