Skip to content

Commit 26a2b09

Browse files
committed
Migration from celery to django-task-scheduler
1 parent d78f705 commit 26a2b09

File tree

15 files changed

+40
-287
lines changed

15 files changed

+40
-287
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ PastedIR/
3535
├── 📁 website/ # Web application views
3636
├── 📁 templates/ # HTML templates
3737
├── 📁 static/ # CSS, JS, images
38+
├── 📁 compose/ # Docker configurations
3839
├── 🐳 docker-compose.yml # Container orchestration
39-
└── 📄 requirements.txt # Python dependencies
40+
└── 📄 pyproject.toml # Python dependencies
4041
```
4142

4243
## 🚀 Quick Start
@@ -45,7 +46,7 @@ PastedIR/
4546
- Python 3.11+
4647
- uv
4748
- Docker & Docker Compose
48-
- Redis (for Celery tasks)
49+
- Redis (for caching and task scheduling)
4950

5051
### 1. Clone the Repository
5152
```bash
@@ -64,7 +65,7 @@ nano .env
6465

6566
### 3. Docker Deployment (Recommended)
6667
```bash
67-
# Start all services
68+
# Start all services (includes PostgreSQL and Redis)
6869
docker-compose up -d
6970

7071
# View logs
@@ -82,7 +83,6 @@ source .venv/bin/activate # Linux/Mac
8283
# or
8384
.venv\Scripts\activate # Windows
8485

85-
8686
# Run migrations
8787
python manage.py migrate
8888

@@ -92,11 +92,8 @@ python manage.py createsuperuser
9292
# Start development server
9393
python manage.py runserver
9494

95-
# Start Celery worker (in another terminal)
96-
celery -A pastebinir worker --loglevel=info
97-
98-
# Start Celery beat (in another terminal)
99-
celery -A pastebinir beat --loglevel=info
95+
# Start scheduler worker (in another terminal)
96+
python manage.py scheduler_worker default
10097
```
10198

10299
## ⚙️ Configuration
@@ -109,8 +106,11 @@ SECRET_KEY=your-secret-key-here
109106
DEBUG=False
110107
ALLOWED_HOSTS=your-domain.com,localhost
111108
112-
# Database
113-
DATABASE_URL=sqlite:///db.sqlite3
109+
# Database (PostgreSQL)
110+
POSTGRES_NAME=postgres
111+
POSTGRES_USER=postgres
112+
POSTGRES_PASSWORD=postgres
113+
POSTGRES_HOST=localhost
114114
115115
# Static Files
116116
STATIC_URL=/static/
@@ -120,7 +120,7 @@ STATIC_ROOT=/static
120120
CSRF_TRUSTED_ORIGINS=https://your-domain.com
121121
BOT_TOKEN=your-bot-token-for-api-calls
122122
123-
# Redis (for Celery)
123+
# Redis (for caching and task scheduling)
124124
REDIS_HOST=localhost
125125
REDIS_PORT=6379
126126
```
@@ -195,8 +195,8 @@ The application supports dark/light mode with automatic theme switching. Customi
195195
# View application logs
196196
docker-compose logs -f web
197197

198-
# View Celery logs
199-
docker-compose logs -f celery
198+
# View scheduler logs
199+
docker-compose logs -f scheduler
200200
```
201201

202202
### Health Checks

compose/development/django/Dockerfile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,11 @@ RUN chmod +x /entrypoint
4747

4848
# Don't create media and staticfiles directories - they'll be mounted as volumes
4949

50-
# Copy production startup scripts (for celery)
50+
# Copy production startup scripts
5151
COPY --chown=django:django ./compose/production/django/start /start
5252
RUN sed -i 's/\r$//g' /start
5353
RUN chmod +x /start
5454

55-
COPY --chown=django:django ./compose/production/django/celery/worker/start /start-celeryworker
56-
RUN sed -i 's/\r$//g' /start-celeryworker
57-
RUN chmod +x /start-celeryworker
58-
59-
COPY --chown=django:django ./compose/production/django/celery/beat/start /start-celerybeat
60-
RUN sed -i 's/\r$//g' /start-celerybeat
61-
RUN chmod +x /start-celerybeat
62-
6355
# copy application code to WORKDIR
6456
COPY --chown=django:django . ${APP_HOME}
6557

compose/production/django/Dockerfile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ COPY --chown=django:django ./compose/production/django/start /start
6767
RUN sed -i 's/\r$//g' /start
6868
RUN chmod +x /start
6969

70-
COPY --chown=django:django ./compose/production/django/celery/worker/start /start-celeryworker
71-
RUN sed -i 's/\r$//g' /start-celeryworker
72-
RUN chmod +x /start-celeryworker
73-
74-
75-
COPY --chown=django:django ./compose/production/django/celery/beat/start /start-celerybeat
76-
RUN sed -i 's/\r$//g' /start-celerybeat
77-
RUN chmod +x /start-celerybeat
78-
7970
# copy application code to WORKDIR
8071
COPY --chown=django:django . ${APP_HOME}
8172

compose/production/django/celery/beat/start

Lines changed: 0 additions & 8 deletions
This file was deleted.

compose/production/django/celery/worker/start

Lines changed: 0 additions & 8 deletions
This file was deleted.

docker-compose.dev.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,12 @@ services:
5454
- production_redis_data:/data
5555

5656

57-
celeryworker:
58-
<<: *django
59-
build:
60-
context: .
61-
dockerfile: ./compose/development/django/Dockerfile
62-
command: /start-celeryworker
63-
volumes:
64-
- .:/app:ro # Mount entire project for live development
65-
environment:
66-
- DEBUG=True
67-
- PYTHONPATH=/app
68-
6957
scheduler:
7058
<<: *django
7159
build:
7260
context: .
7361
dockerfile: ./compose/development/django/Dockerfile
74-
command: python manage.py run_scheduler
62+
command: python manage.py scheduler_worker default
7563
volumes:
7664
- .:/app:ro # Mount entire project for live development
7765
environment:

docker-compose.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,8 @@ services:
5656
- production_redis_data:/data
5757

5858

59-
celeryworker:
59+
scheduler:
6060
<<: *django
61-
image: printir_production_celeryworker
62-
command: /start-celeryworker
63-
64-
celerybeat:
65-
<<: *django
66-
image: printir_production_celerybeat
67-
command: /start-celerybeat
61+
image: printir_production_scheduler
62+
command: python manage.py scheduler_worker default
6863

pastebinir/__init__.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

pastebinir/celery.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

pastebinir/settings.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
'health_check.cache',
5353
'health_check.storage',
5454
'health_check.contrib.migrations',
55-
'health_check.contrib.celery', # requires celery
56-
'health_check.contrib.celery_ping', # requires celery
55+
5756
'health_check.contrib.redis', # requires Redis broker
5857
'scheduler', # django-tasks-scheduler
5958
]
@@ -232,21 +231,8 @@
232231
LANGUAGE_CACHE_KEY = 'all_languages'
233232
LANGUAGE_CACHE_TIMEOUT = 3600 # 1 hour
234233

235-
# Celery Configuration
236-
CELERY_BROKER_URL = 'redis://redis:6379/0'
237-
CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
238-
CELERY_ACCEPT_CONTENT = ['json']
239-
CELERY_TASK_SERIALIZER = 'json'
240-
CELERY_RESULT_SERIALIZER = 'json'
241-
CELERY_TIMEZONE = 'UTC'
242-
243-
# Celery Beat Schedule
244-
CELERY_BEAT_SCHEDULE = {
245-
'cleanup-expired-pastes': {
246-
'task': 'website.tasks.cleanup_expired_pastes',
247-
'schedule': 600.0, # 10 minutes
248-
},
249-
}
234+
235+
# Scheduled tasks are now defined in website/scheduler_tasks.py
250236

251237

252238

@@ -261,8 +247,8 @@
261247
'MEMORY_MIN': 100, # in MB
262248
'SUBSETS': {
263249
'startup-probe': ['MigrationsHealthCheck', 'DatabaseBackend'],
264-
'liveness-probe': ['DatabaseBackend', 'CacheBackend', 'CeleryHealthCheck'],
265-
'readiness-probe': ['DatabaseBackend', 'CacheBackend', 'CeleryHealthCheck', 'RedisHealthCheck'],
250+
'liveness-probe': ['DatabaseBackend', 'CacheBackend'],
251+
'readiness-probe': ['DatabaseBackend', 'CacheBackend', 'RedisHealthCheck'],
266252
},
267253
}
268254

0 commit comments

Comments
 (0)