{"id":299300,"date":"2020-02-26T15:00:28","date_gmt":"2020-02-26T15:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=299300"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-02-26T15:00:28","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=299300","title":{"rendered":"Python-Celery in Windows with Docker managing"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/490040\/\">\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b &#8216;<i>\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e<\/i>&#8216; \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c Celery \u0438\u0437-\u043f\u043e\u0434 Windows \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u0442\u0435\u0439 \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a:<\/p>\n<pre><code class=\"bash\">&gt; celery worker --app=demo_app.core --pool=solo --loglevel=INFO<\/code><\/pre>\n<p>  \u041d\u043e, \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0443\u0436\u043d\u0430 Unix-\u0441\u0438\u0441\u0442\u0435\u043c\u0430. \u0415\u0441\u043b\u0438 \u0443 \u0412\u0430\u0441 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u043a\u0430\u043a \u0440\u043e\u0434\u043d\u0443\u044e, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f\u2026) \u041d\u0443 \u0430 \u0435\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e, \u0442\u043e \u0432\u044b\u0445\u043e\u0434 \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0438 \u044d\u0442\u043e Docker, \u0430 \u0442\u0430\u043a\u0436\u0435 WSL. \u0415\u0441\u043b\u0438 \u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0442\u0430\u043a\u0438\u0435 \u00ab\u043a\u0440\u0443\u0442\u044b\u0435\u00bb IDE, \u043a\u0430\u043a PyCharm, \u0442\u043e \u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f, \u0432\u0435\u0434\u044c \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 \u0441 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0438\u0437 WSL \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 pip \u0441\u043a\u0435\u043b\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u0435\u0439.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041d\u043e \u0441 <b>Docker <\/b>\u0432\u0441\u0435 \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443. \u0414\u043b\u044f \u043a\u0440\u0443\u0442\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f Windows 10 Pro, \u0442\u0430\u043a \u043a\u0430\u043a Home-\u0432\u0435\u0440\u0441\u0438\u044f \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c <a href=\"https:\/\/docs.docker.com\/docker-for-windows\/install\/\">Docker<\/a>. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0432 \u0442\u0440\u0435\u0435, \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u043e\u043a.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pb\/7i\/ys\/pb7iysypwuwvvmaleaamwqnxzvk.png\" alt=\"image\"><\/p>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 Django. \u0417\u0434\u0435\u0441\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e 2.2. \u0411\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u0442\u0430\u043a\u0443\u044e:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yh\/bt\/8k\/yhbt8kzaulz5qtme6j0bklias0m.png\" alt=\"image\"><\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <a href=\"https:\/\/pypi.org\/project\/celery\/\">Celery<\/a> and <a href=\"https:\/\/pypi.org\/project\/redis\/\">Redis<\/a> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0440\u043e\u043a\u0435\u0440\u0430.<\/p>\n<p>  <b>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438:<\/b><\/p>\n<pre><code class=\"python\"># core\/settings.py  CELERY_BROKER_URL = 'redis:\/\/demo_app_redis:6379' CELERY_ACCEPT_CONTENT = ['json']  CELERY_TASK_SERIALIZER = 'json' <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\"># core\/celery.py from __future__ import absolute_import, unicode_literals import os from celery import Celery  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') app = Celery('core') app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks() <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\"># core\/__init__.py from __future__ import absolute_import, unicode_literals from .celery import app as celery_app  __all__ = ('celery_app',) <\/code><\/pre>\n<p>  <i>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u043e\u0435 django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/i> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0448\u0438 <b>\u0437\u0430\u0434\u0430\u0447\u0438<\/b> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\"># app\/tasks.py from celery.task import periodic_task from datetime import timedelta  @periodic_task(run_every=(timedelta(seconds=5)), name='hello') def hello():     print(&quot;Hello there&quot;) <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c <i>Dockerfile<\/i> \u0438 <i>docker-compose.yml<\/i> \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"xml\"># Dockerfile FROM python:3.7 RUN pip install pipenv RUN mkdir \/code WORKDIR \/code COPY Pipfile* \/code\/ RUN pipenv install --system --deploy --ignore-pipfile ADD core \/code\/ <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"xml\"># docker-compose.yml version: '3'  services:   redis:     image: redis     restart: always     container_name: 'demo_app_redis'     command: redis-server     ports:       - '6379:6379'   web:     build: .     restart: always     container_name: 'demo_app_django'     command: python manage.py runserver 0.0.0.0:8000     volumes:       - .:\/code     ports:       - '8000:8000'   celery:     build: .     container_name: 'demo_app_celery'     command: celery -A core worker -B     volumes:       - .:\/code     links:       - redis     depends_on:       - web       - redis <\/code><\/pre>\n<p>  \u0418 \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/cq\/ns\/gv\/cqnsgvm4l-aipkp1xkzgv0vdfc0.png\" alt=\"image\"><\/p>\n<p>  \u0414\u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u0441\u0435\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 pipenv-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435. \u0412 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u044d\u0442\u043e:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vt\/s8\/p1\/vts8p1keajxsof32yd96qau9jcm.png\" alt=\"image\"><\/p>\n<p>  <i>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u043a\u0440\u0443\u0442\u043e<\/i>! \u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043c\u043e\u0436\u043d\u043e \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/da\/of\/4-\/daof4-dwmegxrm6ifjnmxjigrqq.png\" alt=\"image\"><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/kk\/ph\/wq\/kkphwqomnanzo_takxcjysjnwl0.png\" alt=\"image\"><\/p>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c \u0443 2 \u043e\u0431\u0440\u0430\u0437\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e Dockerfile \u043e\u0434\u0438\u043d ID.<\/p>\n<p>  <b>\u041d\u043e \u0442\u0430\u043a \u0436\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GUI:<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xp\/99\/v0\/xp99v0yz_vca3vmzvbsdbdpq0k0.jpeg\" alt=\"image\"><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g2\/ik\/gu\/g2ikguy5eqeugm2p4madojn-b2i.jpeg\" alt=\"image\"><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u0432\u043e\u0442 \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\/\u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c, \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sm\/e7\/wg\/sme7wgkzs7lq-is5wfxyymvmaes.png\" alt=\"image\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/490040\/\"> https:\/\/habr.com\/ru\/post\/490040\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/490040\/\">\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b &#8216;<i>\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e<\/i>&#8216; \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c Celery \u0438\u0437-\u043f\u043e\u0434 Windows \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u0442\u0435\u0439 \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a:<\/p>\n<pre><code class=\"bash\">&gt; celery worker --app=demo_app.core --pool=solo --loglevel=INFO<\/code><\/pre>\n<p>  \u041d\u043e, \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0443\u0436\u043d\u0430 Unix-\u0441\u0438\u0441\u0442\u0435\u043c\u0430. \u0415\u0441\u043b\u0438 \u0443 \u0412\u0430\u0441 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u043a\u0430\u043a \u0440\u043e\u0434\u043d\u0443\u044e, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f\u2026) \u041d\u0443 \u0430 \u0435\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e, \u0442\u043e \u0432\u044b\u0445\u043e\u0434 \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0438 \u044d\u0442\u043e Docker, \u0430 \u0442\u0430\u043a\u0436\u0435 WSL. \u0415\u0441\u043b\u0438 \u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0442\u0430\u043a\u0438\u0435 \u00ab\u043a\u0440\u0443\u0442\u044b\u0435\u00bb IDE, \u043a\u0430\u043a PyCharm, \u0442\u043e \u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f, \u0432\u0435\u0434\u044c \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 \u0441 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0438\u0437 WSL \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 pip \u0441\u043a\u0435\u043b\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u0435\u0439.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-299300","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299300"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299300\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}