PieApp Workers
Workers are long-running background processes that run alongside your app, such as Laravel queue workers. PieApp starts them with your app, restarts them if they exit, and stops them gracefully when you deploy.
Workers are defined in a pie.json file at the root of your repository, the same file used for cronjobs. They are included with every paid plan at no extra cost.
Defining Workers
Add a workers array to pie.json:
{
"workers": [
{
"name": "default",
"command": "php artisan queue:work --tries=3 --max-time=3600",
"processes": 1
}
]
}
| Key | Required | Description |
|---|---|---|
| command | Yes | The command to run. Must be a single line, up to 500 characters. |
| name | No | A label shown in the dashboard and logs. Letters, numbers, - and _. Defaults to worker-1, worker-2 and so on. |
| processes | No | How many copies of this command to run. Defaults to 1. |
Changes to pie.json take effect after the next deployment. You can see your workers and how many processes are running in the Crons & workers tab of your app.
Plans and Limits
Workers share your app's CPU and memory, so the number of processes depends on your plan:
| Plan | Worker processes |
|---|---|
| Free | Not available |
| 1 vCPU plans | Up to 2 |
| 2 vCPU plans and up | Up to 4 |
- The limit counts processes across all workers. If pie.json asks for more, the first ones in the list run and the rest wait until you move to a larger plan.
- A pie.json can define at most 4 processes in total.
- Changing your plan starts or stops workers right away, no new deployment needed.
How Workers Run
- Commands run in /app, as the same user as your app, with your .env and secret files in place.
- If a worker exits or crashes, it is restarted after 2 seconds.
- Worker output appears in the Runtime logs tab, next to your app's logs.
- On every deployment, your new code starts in a new container, so there is no need to run queue:restart.
Graceful shutdown
When a deployment replaces your app, each worker receives a stop signal (SIGTERM) and has up to 60 seconds to finish before it is stopped. Laravel's queue:work finishes the job it is working on and then exits.
For the signal to reach your process, use a single command. Avoid chaining with && or ; and avoid pipes. If you need a setup step, put it in a script that ends with exec, so the script is replaced by your process:
#!/bin/sh
php artisan config:cache
exec php artisan queue:work --tries=3
Keep jobs that can run longer than 60 seconds safe to retry, since a deployment can stop them part way.
Laravel Queues
1. Choose a queue backend
Workers need a queue that lives outside the container. Set QUEUE_CONNECTION in your app's Environment tab:
- database: uses your app's database. Create the jobs table with php artisan make:queue-table (Laravel 11 and later, or queue:table on older versions) and run your migrations. Works with PieDB or PieGres.
- redis: faster, and needed for Horizon. Use PieCache and set the REDIS_* variables.
Do not use the sync driver, it runs jobs during the web request instead of on a worker.
2. Add the worker
{
"workers": [
{
"name": "default",
"command": "php artisan queue:work --tries=3 --max-time=3600",
"processes": 2
}
]
}
--max-time makes the worker exit after an hour, and PieApp starts a fresh one. This keeps memory use in check for long-running workers.
Multiple queues
Run a separate worker per queue to keep slow jobs from blocking urgent ones:
{
"workers": [
{ "name": "high", "command": "php artisan queue:work --queue=high,default" },
{ "name": "emails", "command": "php artisan queue:work --queue=emails" }
]
}
Horizon
If you use Laravel Horizon with Redis, run it as one worker. Horizon starts its own processes, configured in config/horizon.php, so keep those within your plan's CPU and memory:
{
"workers": [
{ "name": "horizon", "command": "php artisan horizon" }
]
}
Scheduler
Workers and crons work together. Run the scheduler as a cron in the same pie.json:
{
"crons": [
{ "schedule": "* * * * *", "command": "/usr/bin/php /app/artisan schedule:run >> /dev/null 2>&1" }
],
"workers": [
{ "name": "default", "command": "php artisan queue:work --tries=3 --max-time=3600" }
]
}
Node.js
Workers are not limited to Laravel. Any long-running command works, for example a BullMQ worker:
{
"workers": [
{ "name": "jobs", "command": "node /app/worker.js" }
]
}
Handle SIGTERM in your script to finish the current job before exiting.
Help
Facing difficulties? Use the chat box on the bottom-right corner of this page to reach us.

