Version: 2.11

Background Tasks

Background tasks are functions that run in a separate process from the main application and are used to perform actions that are either asynchronous or need to be run periodically. This section describes the periodic tasks in Saleor.

warning

Periodic tasks in Saleor are not pre-configured to run automatically. When running Saleor in production, you need to make sure to configure them using the task runner of your choice.

note

Heroku users can use the Scheduler add-on to call commands at a predefined time automatically.

Updating minimal variant prices

Products in Saleor have the minimal_variant_price field, which is used to store the currently lowest price of a product, taking into account variant prices (which may be different than the base product price) and active sales. Minimal variant price are useful when you want to sort the products by price. When creating new sales and changing product prices, we automatically recalculate the minimal variant price. But if a sale has an end date, minimal product prices should be recalculated again after it ends. In this case, a background task comes in handy.

To recalculate the minimal variant prices run the following command:

$ python manage.py update_all_products_minimal_variant_prices

The recommended interval for running this command is once a day.

Fetching currency conversion rates

Saleor provides the integration with Open Exchange Rates API, which allows you to show product prices in customers’ local currencies. Local prices are only provided as an estimate; customers are still charged in your store’s default currency.

To enable the integration, you need an Open Exchange Rates account. Unless you need to update the exchange rates multiple times a day, the free Subscription Plan should be enough, but do consider paying for the wonderful service that Open Exchange Rates provides. Start by signing up and creating an “App ID”.

Export the following environment variable:

  • OPENEXCHANGERATES_API_KEY - Your store’s Open Exchange Rates “App ID”.

To update the exchange rates run the following command:

$ python manage.py update_exchange_rates --all

The recommended interval for running this command is once a day.