从celery容器到redis的通信问题

dz6r00yl  于 6个月前  发布在  Redis
关注(0)|答案(1)|浏览(62)

我正在Docker化我的旧项目,但我遇到了这个错误:

> Traceback (most recent call last):File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 624, in
> connectsock = self.retry.call_with_retry(File
> "/venv/lib/python3.10/site-packages/redis/retry.py", line 46, in
> call_with_retryreturn do()File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 625, in
> <lambda>lambda: self._connect(), lambda error:
> self.disconnect(error)File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 690, in
> _connectraise errFile "/venv/lib/python3.10/site-packages/redis/connection.py", line 678, in
> _connectsock.connect(socket_address)
> 
> During handling of the above exception ([Errno 99] Address not
> available), another exception occurred:File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 119, in reconnect_on_erroryieldFile
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 169, in _consume_fromself._pubsub.subscribe(key)File
> "/venv/lib/python3.10/site-packages/redis/client.py", line 1623, in
> subscriberet_val = self.execute_command("SUBSCRIBE",
> *new_channels.keys())File "/venv/lib/python3.10/site-packages/redis/client.py", line 1458, in
> execute_commandself.connection =
> self.connection_pool.get_connection(File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 1427,
> in get_connectionconnection.connect()File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 630, in
> connectraise ConnectionError(self._error_message(e))
> 
> During handling of the above exception (Error 99 connecting to
> localhost:6379. Address not available.), another exception
> occurred:File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 624, in
> connectsock = self.retry.call_with_retry(File
> "/venv/lib/python3.10/site-packages/redis/retry.py", line 46, in
> call_with_retryreturn do()File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 625, in
> <lambda>lambda: self._connect(), lambda error:
> self.disconnect(error)File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 690, in
> _connectraise errFile "/venv/lib/python3.10/site-packages/redis/connection.py", line 678, in
> _connectsock.connect(socket_address)
> 
> During handling of the above exception ([Errno 99] Address not
> available), another exception occurred:File
> "/venv/lib/python3.10/site-packages/kombu/connection.py", line 446, in
> _reraise_as_library_errorsyieldFile "/venv/lib/python3.10/site-packages/celery/app/base.py", line 787, in
> send_taskself.backend.on_task_call(P, task_id)File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 365, in on_task_callself.result_consumer.consume_from(task_id)File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 161, in consume_fromreturn self.start(task_id)File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 139, in startself._consume_from(initial_task_id)File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 168, in _consume_fromwith self.reconnect_on_error():File
> "/usr/local/lib/python3.10/contextlib.py", line 153, in
> exitself.gen.throw(typ, value, traceback)File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 122, in reconnect_on_errorself._ensure(self._reconnect_pubsub, ())File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 376, in ensurereturn retry_over_time(File
> "/venv/lib/python3.10/site-packages/kombu/utils/functional.py", line
> 312, in retry_over_timereturn fun(*args, **kwargs)File
> "/venv/lib/python3.10/site-packages/celery/backends/redis.py", line
> 106, in _reconnect_pubsubmetas =
> self.backend.client.mget(self.subscribed_to)File
> "/venv/lib/python3.10/site-packages/redis/commands/core.py", line
> 1976, in mgetreturn self.execute_command("MGET", *args, **options)File
> "/venv/lib/python3.10/site-packages/redis/client.py", line 1255, in
> execute_commandconn = self.connection or
> pool.get_connection(command_name, **options)File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 1427,
> in get_connectionconnection.connect()File
> "/venv/lib/python3.10/site-packages/redis/connection.py", line 630, in
> connectraise ConnectionError(self._error_message(e))
> 
> The above exception (Error 99 connecting to localhost:6379. Address
> not available.) was the direct cause of the following exception:File
> "/venv/lib/python3.10/site-packages/asgiref/sync.py", line 486, in
> thread_handlerraise exc_info[1]File
> "/venv/lib/python3.10/site-packages/django/core/handlers/exception.py",
> line 42, in innerresponse = await get_response(request)File
> "/venv/lib/python3.10/site-packages/django/core/handlers/base.py",
> line 253, in _get_response_asyncresponse = await wrapped_callback(File
> "/venv/lib/python3.10/site-packages/asgiref/sync.py", line 448, in
> callret = await asyncio.wait_for(future, timeout=None)File
> "/usr/local/lib/python3.10/asyncio/tasks.py", line 408, in
> wait_forreturn await futFile
> "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in
> runresult = self.fn(*self.args, **self.kwargs)File
> "/venv/lib/python3.10/site-packages/asgiref/sync.py", line 490, in
> thread_handlerreturn func(*args, **kwargs)File
> "/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py",
> line 23, in _wrapped_viewreturn view_func(request, *args,
> **kwargs)File "/helpdeskproject/helpdesk/views.py", line 76, in hometarefa.save()File
> "/venv/lib/python3.10/site-packages/django/db/models/base.py", line
> 812, in saveself.save_base(File
> "/venv/lib/python3.10/site-packages/django/db/models/base.py", line
> 878, in save_basepost_save.send(File
> "/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py",
> line 176, in sendreturn [File
> "/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py",
> line 177, in <listcomp>
> 
> (receiver, receiver(signal=self, sender=sender, **named))
> 
> File "/helpdeskproject/helpdesk/signals.py", line 165, in
> notify_on_ticket_createdcreate_notification(File
> "/helpdeskproject/notifications/models.py", line 48, in
> create_notificationnotification.save()File
> "/venv/lib/python3.10/site-packages/django/db/models/base.py", line
> 812, in saveself.save_base(File
> "/venv/lib/python3.10/site-packages/django/db/models/base.py", line
> 878, in save_basepost_save.send(File
> "/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py",
> line 176, in sendreturn [File
> "/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py",
> line 177, in <listcomp>
> 
> (receiver, receiver(signal=self, sender=sender, **named))
> 
> File "/helpdeskproject/notifications/signals.py", line 22, in
> notify_allnotification_system.notify(instance)File
> "/helpdeskproject/notifications/notification_system.py", line 24, in
> notifyobserver.update(notification)File
> "/helpdeskproject/notifications/notification_channels/channels.py",
> line 10, in
> updatenotification_service.send_notification(notification)File
> "/helpdeskproject/notifications/notification_services/skype_notification.py",
> line 14, in
> send_notificationself.send_warning_notification(notification.user)File
> "/helpdeskproject/notifications/notification_services/skype_notification.py",
> line 39, in
> send_warning_notificationsend_skype_notification.delay(skype_id,
> message)File "/venv/lib/python3.10/site-packages/celery/app/task.py",
> line 425, in delayreturn self.apply_async(args, kwargs)File
> "/venv/lib/python3.10/site-packages/celery/app/task.py", line 575, in
> apply_asyncreturn app.send_task(File
> "/venv/lib/python3.10/site-packages/celery/app/base.py", line 785, in
> send_taskwith P.connection._reraise_as_library_errors():File
> "/usr/local/lib/python3.10/contextlib.py", line 153, in
> exitself.gen.throw(typ, value, traceback)File
> "/venv/lib/python3.10/site-packages/kombu/connection.py", line 450, in
> _reraise_as_library_errorsraise ConnectionError(str(exc)) from exc
> 
> Exception Type: OperationalError at /Exception Value: Error 99
> connecting to localhost:6379. Address not available. ```

字符串

roqulrg3

roqulrg31#

Dockerfile.celery

FROM python:3.10.13-alpine

COPY helpdeskproject /helpdeskproject

WORKDIR /helpdeskproject

RUN apk add build-base curl RUN python -m venv /venv && \   /venv/bin/pip install --upgrade pip && \   /venv/bin/pip install -r /helpdeskproject/requirements.txt && \   adduser --disabled-password
--no-create-home duser

ENV PATH="/venv/bin:$PATH"

字符串
docker-compose.yml

version: '3.9'

networks:   infra:

services:   nginx:
    container_name: nginx
    build:
      context: .
      dockerfile: Dockerfile.nginx
    ports:
      - 80:80
    volumes:
     - ./helpdeskproject/static:/static
     - ./helpdeskproject/media:/media
    depends_on:
      - helpdesk
    networks:
      - infra

  helpdesk:
    container_name: helpdesk
    build:
      context: .
      dockerfile: Dockerfile.django
    ports:
      - 8000:8000
    volumes:
     - ./helpdeskproject:/helpdeskproject
    env_file: 
      - ./helpdeskproject/.env
    networks:
      - infra

  psql:
    container_name: psql
    image: postgres:13-alpine
    volumes:
      - ./data/postgres/data:/var/lib/postgresql/data/
    env_file:
      - ./helpdeskproject/.env
    networks:
      - infra

  redis:
    container_name: redis
    image: redis
    ports:
      - 6379:6379
    expose:
      - 6379
    env_file:
      - ./helpdeskproject/.env
    networks:
      - infra

  celery:
    container_name: celery
    build:
      context: .
      dockerfile: Dockerfile.celery
    working_dir: /helpdeskproject
    volumes:
     - ./helpdeskproject:/helpdeskproject
    command: celery -A helpdeskproject worker --pool=solo -l INFO -E
    env_file:
      - ./helpdeskproject/.env
    environment:
      - REDIS_URL=redis://redis:6379/
    depends_on:
      - redis
      - helpdesk
      - psql
    networks:
      - infra

相关问题