Skip to content

Commit

Permalink
Fudging around with celery some more...
Browse files Browse the repository at this point in the history
  • Loading branch information
joshSzep committed Jul 22, 2024
1 parent 155299c commit 85c95e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions hangul_tutor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .celery import app as celery_app # noqa: F401


__all__ = ("celery_app",)
17 changes: 13 additions & 4 deletions hangul_tutor/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
import time

import celery
from django.conf import settings


# Set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hangul_tutor.settings")

# Instantiate Celery once per Django start.
app = celery.Celery("hangul_tutor")
app.config_from_object("django.conf:settings")
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

# 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 apps.
app.autodiscover_tasks()


logger = logging.getLogger(__name__)


@app.task(bind=True)
@app.task(bind=True, ignore_result=True)
def debug_task(self):
logger.info("Starting debug task")
time.sleep(5)
Expand Down
7 changes: 5 additions & 2 deletions hangul_tutor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,21 @@
}

# CELERY STUFF
BROKER_URL = os.environ.get(
CELERY_BROKER_URL = os.environ.get(
"CELERY_BROKER_URL",
"redis://localhost:6379",
)
CELERY_RESULT_BACKEND = os.environ.get(
"CELERY_RESULT_BACKEND",
BROKER_URL,
CELERY_BROKER_URL,
)
CELERY_ACCEPT_CONTENT = ["application/json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_TIMEZONE = "UTC"
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60
CELERY_TASK_SOFT_TIME_LIMIT = 20 * 60

AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
Expand Down

0 comments on commit 85c95e9

Please sign in to comment.