> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aikeedo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Background Jobs & Queue

> How Aikeedo runs slow work and scheduled tasks in the background: what cron does, when to add a background worker, and how to read the Queue page.

## Introduction

Some work is too slow to do while a user waits, such as importing content or refreshing a connector's tools. Aikeedo puts that work on a **queue** as **jobs**, and runs them in the background. Recurring work, such as renewing subscriptions, runs as **scheduled tasks**, each on its own schedule.

Both run from the [cron job](https://docs.aikeedo.com/setup/initial-setup.md#setting-up-the-cron-job), so cron is all you need, including on shared hosting. For faster background work, you can also keep a **background worker** running.

> [!NOTE]
>
> The scheduled tasks on this page are Aikeedo's own recurring work. They are not the [scheduled tasks](https://docs.aikeedo.com/advanced/scheduled-tasks.md) your users create to run chat instructions on a schedule, although those are started by one of them: **Run due scheduled tasks**.

## How it works

Cron runs `cron.php` every minute. Each run:

1. **Runs the scheduled tasks that are due.** Each task runs on its own, so one that fails doesn't stop the others. Its result shows on the Queue page.
2. **Works the queue for about 50 seconds**, unless a background worker that handles every queue is running. A job added between cron runs therefore waits up to a minute.

A failed job is retried a few times with a pause in between. If it keeps failing, it is kept as a **failed job** for 30 days, so you can see why and retry it.

While an update is unfinished, cron does nothing until it is finished. See [How to Update](https://docs.aikeedo.com/versioning/how-to-update.md).

> [!NOTE]
>
> Keep cron running every minute even if you add a background worker. The worker runs jobs; scheduled tasks still run from cron.

## The Queue page

Go to **Settings → System → Queue**.

| Section | What it shows |
| - | - |
| **Overview** | The **Adapter** in use, and how many jobs are **Waiting**, **Running** and **Failed**, and how many **Workers** are running. |
| **Workers** | The workers that are running: background workers, and cron's own runs, marked **Cron**. Each shows when it started, when it was last seen and how many jobs it has done, with a **Restart** action. **Restart all** asks every background worker to finish its current job and start again. |
| **Waiting jobs** | The next jobs to run. |
| **Failed jobs** | Jobs that failed for good, with their error. Retry or delete them one by one. |
| **Scheduled tasks** | Every task with its schedule, last run and status: **Succeeded**, **Failed**, **Running** or **Never run**. |
| **Run a background worker** | Ready-to-use configurations for your server. See [below](#running-a-background-worker). |

When there are more workers, waiting jobs or failed jobs than the section shows, **View all** opens the full list.

Click any job, worker or task to see its details:

* **Job**: its name, queue, status, attempts, timeout, when it was added and when it is due, and its data. A failed job also shows its error and stack trace, with **Retry**.
* **Worker**: the job it is running, who started it, the queues it works, jobs done, memory, when it will exit, and **Restart**.
* **Task**: its schedule, **Next run**, last run and status, with the error and stack trace if it failed.

### Jobs and Workers pages

* **Jobs** lists every job, with **Waiting** and **Failed** tabs and a search. The **Failed** tab has **Retry all** and **Delete all**.
* **Workers** lists every running worker, with a search, a **Started by** filter (**Process manager** or **Cron**) and **Restart all**.

### Status page

The **Status** page in the admin menu also has **Cron** and **Queue** rows. They warn when cron hasn't run for more than five minutes, when scheduled tasks are failing, and when jobs have failed.

## Scheduled tasks

These are the tasks Aikeedo runs on its own. Plugins can add more, which also appear on the Queue page. Times are in UTC.

| Task | Runs |
| - | - |
| Run plugin cron listeners | Every minute |
| Renew subscriptions | Every minute |
| End expired subscriptions | Every minute |
| Calculate MRR | Every minute |
| Retry invoices | Every minute. See [Invoicing](https://docs.aikeedo.com/billing/invoicing.md#retries). |
| Send delayed purchase confirmations | Every 5 minutes |
| Run due scheduled tasks | Every minute. Starts your users' [scheduled tasks](https://docs.aikeedo.com/advanced/scheduled-tasks.md). |
| End stuck generations | Every 5 minutes |
| Delete expired private items | Every minute |
| Convert legacy messages | Every minute |
| Refresh connector tools | Every minute, for connections that are due |
| Delete expired connector sign-ins | Every hour |
| Resume stalled imports | Every 5 minutes |
| Prune cache | Every hour |
| Delete old failed jobs | Daily at 04:30. Failed jobs are kept for 30 days. |
| Delete old notifications | Daily at 04:45. See [Notifications](https://docs.aikeedo.com/advanced/notifications.md#retention). |

## Running a background worker

A background worker is a process that keeps running and starts each job as soon as it is added. It is optional. Use one when jobs should start right away, or when you have many of them.

Keep it running with a process manager such as **Supervisor** or **systemd**. The process manager starts the worker when the server boots and restarts it if it stops. You need only one of them.

> [!TIP]
>
> The **Run a background worker** section of the Queue page shows these configurations with your paths, PHP binary and web server user filled in. Copy them from there.

> [tab] Supervisor
>
> 1. Install Supervisor if it isn't installed: `sudo apt install supervisor`
> 2. Save this as `/etc/supervisor/conf.d/aikeedo-worker.conf`:
>
> ```ini theme={null}
> [program:aikeedo-worker]
> command=/usr/bin/php /path/to/aikeedo/bin/console app:queue:work --time-limit=3600
> directory=/path/to/aikeedo
> user=www-data
> numprocs=1
> autostart=true
> autorestart=true
> stopwaitsecs=660
> redirect_stderr=true
> stdout_logfile=/path/to/aikeedo/var/log/worker.log
> ```
>
> 3. Load it and start the worker:
>
> ```bash theme={null}
> sudo supervisorctl reread
> sudo supervisorctl update
> ```
>
> 4. Check that it is running: `sudo supervisorctl status aikeedo-worker`

> [tab] systemd
>
> 1. Save this as `/etc/systemd/system/aikeedo-worker.service`:
>
> ```ini theme={null}
> [Unit]
> Description=Aikeedo queue worker
> After=network.target
>
> [Service]
> User=www-data
> WorkingDirectory=/path/to/aikeedo
> ExecStart=/usr/bin/php /path/to/aikeedo/bin/console app:queue:work --time-limit=3600
> Restart=always
> RestartSec=3
> TimeoutStopSec=660
>
> [Install]
> WantedBy=multi-user.target
> ```
>
> 2. Start the worker, and start it on every boot:
>
> ```bash theme={null}
> sudo systemctl daemon-reload
> sudo systemctl enable --now aikeedo-worker
> ```
>
> 3. Check that it is running: `sudo systemctl status aikeedo-worker`

Once it is running, the worker appears under **Workers** on the Queue page within a few seconds.

* **Run it as the web server user** (`www-data` above). Otherwise files it creates, such as cache, can't be changed by the application. The worker won't run as `root` unless the application's files belong to `root`.
* **Use the same PHP as the website.** If your server has more than one PHP version, the Queue page's configurations use the website's by its full path, because plain `php` may be another version. Cron and workers log a warning when their PHP differs from the website's.
* **Nothing to do after updates or settings changes.** Workers restart on their own when you update Aikeedo or save settings.

## Queue adapters

The **adapter** is where waiting jobs are kept. Change it with **Change** next to **Adapter** on the Queue page. The list shows only enabled adapters: turn on an adapter from a plugin under **Settings → System → Queue adapters** first.

| Adapter | Use it for |
| - | - |
| **Database** (default) | Any server, including shared hosting. Jobs wait in your database. |
| **Synchronous** | Troubleshooting only. Each job runs immediately, while the user waits. |

The [Queue Adapters](https://docs.aikeedo.com/integrations/queue-adapters/overview.md) plugin adds Redis, Amazon SQS, Azure Queue Storage and Cloudflare Queues, which take that load off your database on busy sites.

If the chosen adapter can't be used, for example because its plugin was removed, jobs fall back to **Database** and a warning is logged.

> [!WARNING]
>
> Switching adapters doesn't move jobs that are already waiting. Let the queue empty first: the Queue page shows how many jobs are waiting.

## Troubleshooting

> [accordion] The Status page says cron has never run or hasn't run recently
>
> Set up the [cron job](https://docs.aikeedo.com/setup/initial-setup.md#setting-up-the-cron-job) to run `cron.php` every minute, as the web server user.

> [accordion] Jobs wait about a minute before they start
>
> That is expected without a background worker: jobs run on the next cron run. Add a [background worker](#running-a-background-worker) to start them right away.

> [accordion] A scheduled task shows Failed
>
> Open it on the Queue page to see the error and stack trace. If **Run plugin cron listeners** fails, the error names the plugin whose listener failed, so you know which one to update or contact.

> [accordion] The worker doesn't appear under Workers
>
> Check the process manager's status command and the worker log. Make sure the configuration uses the website's PHP binary and the right path.

## Need Help?

If you need assistance with Aikeedo:

> [card] [Professional Support](https://aikeedo.com/support/?utm_source=docs\&utm_medium=content)
>
> Get expert help from our team with a paid support subscription

> [card] [Troubleshooting Guide](https://docs.aikeedo.com/setup/troubleshooting.md)
>
> Check common issues and solutions


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.