zwang96-dl / fastapi_celery

For FastAPI + Celery demo purpose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Installation

Virtualenv

python -m venv virtualenv
source virtualenv/bin/activate # deactivate
pip install -r requirements.txt

Redis

For maOS uses Redis server from Docker, and install redis-client manually

docker run --name dev-redis -p 6379:6379 -d redis

# client
brew install redis
# test
redis-cli -h localhost -p 6379 ping
# pong

Start

3 terminals

For Celery worker:

celery -A celery_tasks worker --loglevel=INFO

For Celery Flower:

celery -A celery_tasks flower --address=localhost --port=5566

For FastAPI server:

uvicorn main:app --reload

Play!

FastAPI comes with swagger for free, try add the following payload to http://127.0.0.1:8000/docs#/default/product_task_tasks__post: Swagger

{
    "post_url": "https://dummyjson.com/products/1",
    "delay": 20,
    "payload": {
        "title": "iPhone Galaxy +1"
    }
}

Then check from Flower UI: http://localhost:5566/tasks Flower Demo

Note: For testing purpose https://dummyjson.com/products/1 just a free/fake web api, but we could replace it with any desired http url we'd like.

About

For FastAPI + Celery demo purpose


Languages

Language:Python 65.4%Language:Dockerfile 32.7%Language:Shell 2.0%