usable celery dev setup
commit 5438243b4874879196294a4072f245ebf22afd5d Author: eneller <erikneller@gmx.de> Date: Sat Apr 5 00:12:55 2025 +0200 minor celery commit 3a03c498a7e6acff1afe350ce1ae196375d19029 Author: eneller <erikneller@gmx.de> Date: Fri Apr 4 23:40:23 2025 +0200 begin celery
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# This will make sure the app is always imported when
|
||||
# Django starts so that shared_task will use this app.
|
||||
from .celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
||||
23
src/epub2go_web/celery.py
Normal file
23
src/epub2go_web/celery.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Start Celery workers from src/ using `celery -A epub2go_web worker --loglevel=INFO`
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'epub2go_web.settings')
|
||||
|
||||
app = Celery('epub2go_web')
|
||||
|
||||
# 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()
|
||||
|
||||
|
||||
@app.task(bind=True, ignore_result=True)
|
||||
def debug_task(self):
|
||||
print(f'Request: {self.request!r}')
|
||||
@@ -69,6 +69,19 @@ TEMPLATES = [
|
||||
|
||||
WSGI_APPLICATION = "epub2go_web.wsgi.application"
|
||||
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "db.sqlite3",
|
||||
}
|
||||
}
|
||||
|
||||
# Celery settings
|
||||
CELERY_BROKER_URL = "redis://localhost:6379/0"
|
||||
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"
|
||||
CELERY_TASK_ALWAYS_EAGER = True
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
||||
|
||||
|
||||
11
src/epub2go_web/tasks.py
Normal file
11
src/epub2go_web/tasks.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from celery import shared_task
|
||||
from django.conf import settings
|
||||
|
||||
from epub2go.convert import GBConvert
|
||||
|
||||
converter = GBConvert(downloaddir=settings.MEDIA_ROOT)
|
||||
|
||||
@shared_task
|
||||
def getEpub(book_url):
|
||||
# TODO check for existing file and age
|
||||
return converter.download(book_url)
|
||||
Reference in New Issue
Block a user