-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
477 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import shlex | ||
import os | ||
import subprocess | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.utils import autoreload | ||
from main.celery import CeleryQueue | ||
|
||
|
||
WORKER_STATE_DIR = '/var/run/celery' | ||
|
||
CMD = ( | ||
f"celery -A main worker -Q {','.join(CeleryQueue.ALL_QUEUES)} -E --concurrency=2 -l info" | ||
) | ||
|
||
|
||
def restart_celery(*args, **kwargs): | ||
kill_worker_cmd = 'pkill -9 celery' | ||
subprocess.call(shlex.split(kill_worker_cmd)) | ||
subprocess.call(shlex.split(CMD)) | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
self.stdout.write('Starting celery worker with autoreload...') | ||
if not os.path.exists(WORKER_STATE_DIR): | ||
os.makedirs(WORKER_STATE_DIR) | ||
autoreload.run_with_reloader(restart_celery, args=None, kwargs=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,14 @@ services: | |
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: qb | ||
|
||
redis: | ||
image: redis:latest | ||
healthcheck: | ||
test: ["CMD-SHELL", "redis-cli ping"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
backend: | ||
image: $DOCKER_IMAGE_BACKEND | ||
environment: | ||
|
@@ -25,16 +33,22 @@ services: | |
SESSION_COOKIE_DOMAIN: localhost | ||
CSRF_COOKIE_DOMAIN: localhost | ||
DJANGO_ALLOWED_HOST: '*' | ||
# Database | ||
DJANGO_DB_NAME: qb | ||
DJANGO_DB_USER: postgres | ||
DJANGO_DB_PASSWORD: postgres | ||
DJANGO_DB_PORT: 5432 | ||
DJANGO_DB_HOST: db | ||
DJANGO_CORS_ORIGIN_REGEX_WHITELIST: localhost | ||
# Redis | ||
CELERY_REDIS_URL: redis://redis:6379/1 | ||
DJANGO_CACHE_REDIS_URL: redis://redis:6379/2 | ||
TEST_DJANGO_CACHE_REDIS_URL: redis://redis:6379/12 | ||
EMAIL_FROM: [email protected] | ||
volumes: | ||
- ./coverage/:/code/coverage/ | ||
- ./ci-share/:/ci-share/ | ||
depends_on: | ||
- db | ||
- redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
import celery | ||
|
||
from django.conf import settings | ||
|
||
from main import sentry | ||
|
||
|
||
class Celery(celery.Celery): | ||
def on_configure(self): | ||
if settings.SENTRY_ENABLED: | ||
sentry.init_sentry(**settings.SENTRY_CONFIG) | ||
|
||
|
||
# set the default Django settings module for the 'celery' program. | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings') | ||
|
||
app = Celery('main') | ||
|
||
# Using a string here means the worker doesn't have to serialize | ||
# the configuration object to child processes. | ||
# - namespace='CELERY' means all celery-related configuration keys | ||
# should have a `CELERY_` prefix. | ||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
|
||
# Load task modules from all registered Django app configs. | ||
app.autodiscover_tasks() | ||
app.autodiscover_tasks(['main']) | ||
|
||
|
||
# This is used for ECS Cluster (Each queue needs it's own clusters) | ||
class CeleryQueue(): | ||
DEFAULT = 'CELERY-DEFAULT-QUEUE' | ||
EXPORT_HEAVY = 'CELERY-EXPORT-HEAVY-QUEUE' | ||
|
||
ALL_QUEUES = ( | ||
DEFAULT, | ||
EXPORT_HEAVY, | ||
) | ||
|
||
|
||
app.conf.task_default_queue = CeleryQueue.DEFAULT | ||
|
||
|
||
@app.task(bind=True) | ||
def debug_task(self): | ||
print('Request: {0!r}'.format(self.request)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.