Skip to content

Commit

Permalink
Add task queue section (#1417)
Browse files Browse the repository at this point in the history
* Add task queue section

* Add links

* Explain celery beat setup

* Apply review changes
  • Loading branch information
zedzior authored Jan 14, 2025
1 parent 0eebf8d commit c307cf5
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs/developer/checkout/lifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ To avoid overloading the database, unfinished and unpaid checkouts are automatic
- anonymous checkouts (neither user nor email is set) with lines after 30 days,
- user checkouts (either user or email is set) with lines after 90 days.

:::note
The checkout deletion task is triggered by [celery beat scheduler](developer/running-saleor/task-queue.mdx#periodic-tasks).
This feature will not work without task queue configuration.
:::

## Releasing Funds for Abandoned Checkouts

Payments for items left in the cart by customers who did not complete the purchase will be refunded to the customer's account.
Expand All @@ -58,6 +63,11 @@ The release action is triggered only once. If a subscription for a release event

To fetch paid checkouts, use the below query:

:::note
The releasing funds for abandoned checkouts task is triggered by [celery beat scheduler](developer/running-saleor/task-queue.mdx#periodic-tasks).
This feature will not work without task queue configuration.
:::

```graphql {4}
{
checkouts(first: 10, filter: { authorizeStatus: [PARTIAL, FULL] }) {
Expand Down
5 changes: 5 additions & 0 deletions docs/developer/checkout/order-expiration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ In the above example, orders will expire after 360 minutes (6 hours), and after
Once an unpaid order is created (via [`checkoutComplete`](api-reference/checkout/mutations/checkout-complete.mdx) or [`orderCreateFromCheckout`](api-reference/orders/mutations/order-create-from-checkout.mdx)), it remains in `UNCONFIRMED` status. If the customer does not complete the payment within `expireOrdersAfter` minutes after that, the status will change to `EXPIRED` and stock allocation will be released.
After `deleteExpiredOrdersAfter` days orders in `EXPIRED` status will be deleted and disappear from the order list.

:::note
The order expiration and order deletion tasks are triggered by [celery beat scheduler](developer/running-saleor/task-queue.mdx#periodic-tasks).
This feature will not work without task queue configuration.
:::

## How to disable order expiration

To disable order expiration, set `expireOrdersAfter` to 0.
Expand Down
5 changes: 5 additions & 0 deletions docs/developer/community/contributing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ Also, do not forget about the docstring, especially in a complicated function.
So far, we have mainly used the `GinIndex` and `ilike` operators for searching, but currently, we are testing a new solution with the use of `SearchVector` and `SearchRank`.
You can find it in this PR [#9344](https://github.com/saleor/saleor/pull/9344).

:::note
The search vector update task is triggered by [celery beat scheduler](developer/running-saleor/task-queue.mdx#periodic-tasks).
This feature will not work without task queue configuration.
:::

### API

- Use `id` for mutation inputs instead of `model_name_id`.
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/discounts/promotions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ When multiple promotions apply to one product, only the discount from the promot
The discounts from rules within the single promotion are not summed up.

:::note
The catalogue discounts from promotions are calculated in the background. So the discounted
price will not be instantly visible after promotion creation.
The catalogue discounts from promotions are calculated in the background, triggered by [celery beat scheduler](developer/running-saleor/task-queue.mdx#periodic-tasks).
So the discounted price will not be instantly visible after promotion creation (default interval is set to 30 seconds).
:::

### Examples of the use cases
Expand Down
57 changes: 57 additions & 0 deletions docs/developer/running-saleor/task-queue.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: Task Queue
sidebar_label: Task Queue
---

Some of the Saleor’s functionality depends on a task queue system to manage asynchronous and periodic tasks. We recommend using Celery with Redis as the message broker.
For more information, please visit [official Celery documentation](https://docs.celeryq.dev/en/stable/index.html).


## Periodic tasks

Celery Beat is a scheduler that triggers background tasks at regular intervals.
Some of the Saleor's features can't be used without proper task scheduler setup. In order to start Celery Beat server:

1. Specify `CELERY_BROKER_URL` environmental variable which points to task broker (we recommend using Redis as a broker database):

```shell
set CELERY_BROKER_URL="<broker url>"
```
An example of the Redis broker url, running on localhost and port 6379, looks like: `redis://localhost:6379/0`.

2. Run Celery worker:

```shell
celery --app saleor.celeryconf:app worker -E --loglevel=info
```

3. As a separate process run Celery Beat:

```shell
celery --app saleor.celeryconf:app beat --scheduler saleor.schedulers.schedulers.DatabaseScheduler
```

Below is a list of Saleor features fired up by celery beat with default schedules:

#### Tasks run in intervals:
- Deactivate preorder for variants; 1 hour
- Delete empty allocations; 1 hour
- Delete expired reservations; 1 day
- Delete outdated event data; 1 day
- [Expire orders](developer/checkout/order-expiration.mdx); 5 minutes
- [Recalculate price for catalog promotions](developer/discounts/promotions.mdx#catalogue-promotions); 30 seconds
- [Release funds for abandoned checkouts](developer/checkout/lifecycle.mdx#releasing-funds-for-abandoned-checkouts); 10 minutes
- Remove apps marked as removed; 3 hours
- [Update search vectors](developer/community/contributing.mdx#searching); 20 seconds

#### Tasks run at specific time:
- Deactivate expired gift cards; at 0:00 AM
- [Delete expired checkouts](developer/checkout/lifecycle.mdx#checkout-expiration-and-deletion); at 0:00 AM
- [Delete expired orders](developer/checkout/order-expiration.mdx); at 2:00 AM base on
- Delete old exports files; once per day at 1:00 AM
- Update stocks quantity allocated; once per day at 0:00 AM
- [Promotion toggle](developer/discounts/promotions.mdx); based on promotion's start date and end date

:::important
It is important to understand that without proper task scheduler setup, the actions above will not be triggered.
:::
1 change: 1 addition & 0 deletions sidebars/self-hosting.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const selfHosting = [

"developer/running-saleor/debugging-emails",
"developer/running-saleor/exposing-instance",
"developer/running-saleor/task-queue",

title("Deploying"),

Expand Down
4 changes: 4 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@
"source": "/docs(/3.x|/next)?/category/development",
"destination": "/developer/running-saleor/debugging-emails"
},
{
"source": "/docs(/3.x|/next)?/category/development",
"destination": "/developer/running-saleor/task-queue"
},
{
"source": "/docs(/3.x|/next)?/category/saleor-app-store",
"destination": "/developer/app-store/overview"
Expand Down

0 comments on commit c307cf5

Please sign in to comment.