Skip to content

juangtato-ds/multi-app-python-demo-structure

Repository files navigation

Multi Application Python Demo Structure

This multirepo has a few Python projects. These projects are detailed below. This project can be used for testing purposes and POC.

Contained projects are simple in purpose. These projects must not be used as project templates.

Table of Contents

Projects

celery_tasks

The celery_tasks project has defined 3 simple example task for testing. This tasks are:

  • Concatenate 2 or 3 strings.
  • Calculate the exponential of a number.
  • Calculate the square root of a number.

These tasks have an active wait function that depends on an environment variable called TASK_ARTIFICIAL_DELAY.

celery_cron_jobs

With a periodic time defined by the environment variable CRON_TASK_DELAY, this project call a task automatically.

This task is a simple print with the content of the environment variable.

rest_api

To use the tasks defined fro this celery app, a REST API was implemented. This API have the following endpoints:

  • POST /call_task -> This endpoint can invoke one of the tasks defined in celery_tasks by the following structure:
    {
      "task_name": "sqrt",
      "parameters": [
        4
      ]
    }
  • GET /task/{task_id} -> Recover the status and the result of the task with that ID.
  • GET /health-check -> Returns a dummy JSON with the state of the server.

Deploy

All this projects can be deployed by the command

docker compose up
# or
docker compose up --build

This file contains services for:

  • The broker (rabbitmq).
  • The backend (redis).
  • The celery worker for tasks.
  • The celery worker for cron tasks.
  • The REST API, exposed in port 8000.
  • The flower server, exposed in port 5556.

All the necessary environment variables will be allocated in the .env file.

Appendix - Example of Celery

There is a functional celery example in folder _experimental/celery_poc.

This folder can be used for celery testing purposes.

About

multi-app-python-demo-structure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors