Skip to main content

Installation and Usage

The application to be developed will connect to Omnitron as an Akinon Commerce Cloud (ACC) application and use the user information defined in that application.

In the scenario to be tested in the local environment, the application can be tested without preparing the ACC application by using Omnitron user information. Once the necessary developments are considered ready, the application can be deployed and tested in the application server environment (ACC).

After creating the application on the Acc side, in the project to be used, the + New Application button is used to select the developed application, and the Install button is clicked. The channel and catalog are automatically created in the brand's Omnitron.

This documentation is prepared for Ubuntu-based operating systems.

Once the below steps are completed, everything required for the system will be ready.

Install Python

If the Python version is 3.8 or higher, it is sufficient for the Channel App Template project.

python --version
python3 --version

$: Python 3.8.10

If Python is not installed or your version is outdated, you can complete the Python installation with apt commands. First, it is recommended to run the apt install command. If it cannot find the version, you can proceed with add-apt-repository and then install it again with apt install. If your system's apt can access the package you are looking for, there is no need to add a new ppa in this way.

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update -y
sudo apt install python3.10

The necessary packages to the system are installed by using apt commands. These packages consist of Python package manager pip, version control tool Git, task server Celery, and Redis for Celery's broker requirements.

sudo apt install python3-pip git redis-server python-celery-common
pip3 install --upgrade pip

To avoid conflicts between dependencies of different projects, it is recommended to use a virtual environment. You can visit here for virtual environment installation.

Copy Project and Install Dependencies

The project is copied to the local system. Since git performs the cloning process in the currently active folder in the terminal, it is recommended to navigate to the preferred project folder before running the command.

git clone git@bitbucket.org:akinonteam/channel_app_template.git

You can install the necessary packages for the project with an active virtual environment.

pip install -r requirements.txt

Install Celery and Flower

Celery is an open-source, asynchronous task queue or job queue based on distributed message passing. While it primarily focuses on real-time task processing and execution, it can also manage scheduled tasks. For more information, visit Celery.

Let's run Celery worker processes. User information and some environment variables will have different values for your environment.

  • MAIN_APP_URL: Omnitron URL, excluding the protocol.
  • OMNITRON_CHANNEL_ID: ID of the sales channel to which the application will connect.
  • OMNITRON_CATALOG_ID: Catalog ID of the connected sales channel.
# Export all at once (requires creating the .env file beforehand)
export $(grep -v '^#' .env | xargs)

# Export individually
export MAIN_APP_URL=localhost:8000
export OMNITRON_USERNAME=admin
export OMNITRON_PASSWORD=password
export OMNITRON_CHANNEL_ID=1
export OMNITRON_CATALOG_ID=1
export BROKER_HOST=127.0.0.1
export BROKER_PORT=6379
export BROKER_DATABASE_INDEX=4
export CACHE_HOST=127.0.0.1
export CACHE_PORT=6379
export CACHE_DATABASE_INDEX=3

celery -A channel_app.celery_app worker -l info

By default, the Redis server remains active after installation, especially if it is not shut down. You can test it with the ping command and shut it down using redis-server command.

redis-cli ping
redis-server

Flower is a web-based tool used to view and manage tasks related to Celery. If you do not have regular running jobs to manage or you are using an alternative tool, the installation of Flower is not mandatory.

To install Flower, you need to export some environment variables. Instead of exporting these values individually each time, you can save them in the .env file as KEY=VALUE and then use the command to export them all at once.

# Export all at once (requires creating the .env file beforehand)
export $(grep -v '^#' .env | xargs)

# Export individually
export BROKER_HOST=127.0.0.1
export BROKER_DATABASE_INDEX=4
export BROKER_PORT=6379

celery -A channel_app_template.celery_app flower --address=127.0.0.1 --port=8008

Trigger Tasks via Flower

Flower also allows triggering predefined tasks. To trigger tasks, the example curl request is as follows:

curl --request POST \
--url https://<omnitron-url>.lb.akinoncloud.com/api/task/apply/channel_app_template.app.tasks.<task_name> \
--header 'authorization: Basic <auth token>' \
--header 'content-type: application/json' \
--data '{\n"args":[]\n}'

If the request is successful, it returns the following response with a 200 status code:

HTTP/1.1 200 OK
Content-Length: 71
Content-Type: application/json; charset=UTF-8
{
"state": "SUCCESS",
"task-id": "c60be250-fe52-48df-befb-ac66174076e6",
"result": 3
}

The task-id parameter in the response can be used to query the status of the triggered task via the Flower panel.