Django + Celery. Связь микросервисов

У меня есть 2 отдельных микросервиса. Один сервер django, а другой - celery beat, который должен отправлять API запрос к django раз в минуту.

Docker-compose

version: '3'

services:
  # Django application
  web:
    build: ./WebService
    container_name: web_mysite
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./WebService/:/Microservices/first/WebService/
    ports:
      - "8000:8000"
    depends_on:
      - db_1
    env_file:
      - ./WebService/.env

  # PostgresSQL application
  db_1:
    image: postgres:latest
    container_name: web_postgres
    restart: always
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=user_balance
    ports:
      - "5432:5432"

  # Redis Broker application
  redis:
    image: redis
    container_name: redis
    ports:
      - "6379:6379"

  # Celery application
  celery_worker:
    restart: always
    build:
      context: ./StatisticsService
    container_name: celery_worker
    command: celery -A celery_app worker --loglevel=info
    volumes:
      - ./StatisticsService/:/Microservices/first/StatisticsService/
      - .:/StatisticsService/data
    depends_on:
      - redis

  # Celery-Beat application
  celery_beat:
    restart: always
    build:
      context: ./StatisticsService
    container_name: celery_beat
    command: celery -A celery_app beat --loglevel=info
    volumes:
      - ./StatisticsService/:/Microservices/first/StatisticsService/
      - .:/StatisticsService/data
    depends_on:
      - redis

volumes:
  postgres_data:

Celery-beat func

@celery.task()
def monitoring():
    print("Monitoring balance...")
    with requests.Session() as session:
       res = session.get("http://127.0.0.1:8000/api/v1/transaction/current_balance/", data={"user_id": total})
       if res.status_code == 200:
            res_json = res.json()
            print(res_json)

А в celery worker и beat я получил Ошибка:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /api/v1/transaction/current_balance/ (Причина - NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f924ddea250>: Не удалось установить новое соединение: [Errno 111] Connection refused'))

Как я могу это исправить? Пожалуйста, помогите)

Вернуться на верх