Commit e88e7e7a authored by Roman Shishkin's avatar Roman Shishkin

Celery и Redis конфиги

parent afc9020b
from celery.decorators import task
@task
def topic_index(**kwargs):
index = kwargs.get('index')
key = kwargs.get('key')
topic_id = kwargs.get('topic_id')
topic_blog_id = kwargs.get('topic_blog_id')
topic_user_id = kwargs.get('topic_user_id')
topic_type = kwargs.get('topic_type')
topic_title = kwargs.get('topic_title')
topic_text = kwargs.get('topic_text')
topic_tags = kwargs.get('topic_tags')
topic_date = kwargs.get('topic_date')
topic_publish = kwargs.get('topic_publish')
topic_tags = topic_tags.split(',')
doc_body = {
'blog_id': int(topic_blog_id),
'user_id': int(topic_user_id),
'type': topic_type,
'title': topic_title.strip(),
'text': topic_text.strip(),
'tags': topic_tags,
'date': topic_date,
'publish': topic_publish
}
es.index(index=index, doc_type=key, id=int(topic_id), body=doc_body)
\ No newline at end of file
BROKER_URL = 'redis://127.0.0.1:6379/5'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/6'
CELERY_IMPORTS = ("tasks",)
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'Europe/Moscow'
CELERY_ENABLE_UTC = True
daemonize no
dir /storage
save 1 10
maxclients 100
\ No newline at end of file
......@@ -18,35 +18,62 @@ _templates:
containers:
_base_alpine:
setup:
- !Alpine v3.6
- !AlpineRepo {branch: v3.6, repo: community, tag: community}
- !EnsureDir /config
- !Sh "chmod +r /bin/bbsuid"
- !Alpine v3.6
- !AlpineRepo {branch: v3.6, repo: community, tag: community}
- !EnsureDir /config
- !Sh "chmod +r /bin/bbsuid"
frontend:
setup:
- !Container _base_alpine
- !NpmDependencies
file: package.json
peer: true
optional: true
dev: true
environ:
NODE_PATH: /usr/lib/node_modules
setup:
- !Container _base_alpine
- !NpmDependencies
file: package.json
peer: true
optional: true
dev: true
environ:
NODE_PATH: /usr/lib/node_modules
python:
setup:
- !Container _base_alpine
- !Install [[email protected]]
- !PipConfig
dependencies: true
- !Py3Requirements "requirements.txt"
- !Container _base_alpine
- !Install [[email protected]]
- !PipConfig
dependencies: true
- !Py3Requirements "requirements.txt"
volumes:
<<: *local_volumes
/work/uploads: !Persistent {name: uploads}
environ:
ECHOES_CONFIG: localConfig.LocalDevelopment
redis:
setup:
- !Container _base_alpine
- !Install [redis]
- !EnsureDir /storage
volumes:
<<: *local_volumes
/storage: !Tmpfs
size: 128Mi
mode: 0o1700
celery:
setup:
- !Container _base_alpine
- !Install [python3]
- !PipConfig
dependencies: true
- !Py3Install
- celery[redis]
- !EnsureDir /app
volumes:
<<: *local_volumes
/app: !BindRO /work/celery_tasks
environ:
PYTHONPATH: /config/celeryconfig:/app
CELERY_CONFIG_MODULE: cfg
# Production containers
frontend-production:
setup:
......@@ -112,6 +139,24 @@ commands:
description: Run flask app
run: [python3, run.py]
redis-cli: &redis !Command
container: redis
description: Run redis CLI
run: [redis-cli]
redis: &redis !Command
container: redis
description: Run redis server (cache and broker for celery)
run: redis-server /config/redis.conf
celery: &celery !Command
container: celery
description: Run celery worker for async tasks
user-id: 1
group-id: 1
external-user-id: 0
run: celery worker --pool=solo
init_db: !Command
container: python
description: Init database
......@@ -123,6 +168,7 @@ commands:
run: |
mkdir -vp /work/static
rm -rf /work/static/*
build-static: !Command
prerequisites: [_clean-old-static]
container: frontend
......@@ -139,4 +185,6 @@ commands:
description: Run full server stack
kill-unresponsive-after: 5
children:
flask: *flask
\ No newline at end of file
flask: *flask
redis: *redis
celery: *celery
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment