diff --git a/Config.py b/Config.py index 0d8208c..cbaab77 100644 --- a/Config.py +++ b/Config.py @@ -6,7 +6,8 @@ class Config(BaseSettings): app_name: str = "celery" - redis_url: str = "redis://localhost:6379/0" + redis_broker_url: str = "redis://localhost:6379/15" + redis_beat_url: str = "redis://localhost:6379/14" config = Config() diff --git a/background.py b/background.py index b52676c..78ed287 100644 --- a/background.py +++ b/background.py @@ -6,7 +6,7 @@ from tasks.hello import hello from tasks.welcome import welcome -app = Celery("sidekick", broker=config.redis_url, backend="rpc://") +app = Celery("sidekick", broker=config.redis_broker_url, backend="rpc://") app.config_from_object("celery_config") # tasks @@ -17,4 +17,4 @@ if __name__ == "__main__": - [(hi.delay(2), hello.delay(2), bye.delay(2), welcome.delay(2)) for i in range(1000)] + [(hi.delay(2), hello.delay(2), bye.delay(2), welcome.delay(2)) for i in range(500)] diff --git a/celery_config.py b/celery_config.py index 025f3d1..b978a8e 100644 --- a/celery_config.py +++ b/celery_config.py @@ -1,7 +1,15 @@ +import redbeat +from Config import config from kombu import Exchange, Queue -CELERY_QUEUES = ( +broker_heartbeat = 10 +redbeat_lock_timeout = 60 +beat_max_loop_interval = 10 +redbeat_redis_url = config.redis_beat_url +beat_scheduler = f"{redbeat.__name__}.{redbeat.RedBeatScheduler.__name__}" + +task_queues = ( Queue("hi", Exchange("hi"), routing_key="hi"), Queue("bye", Exchange("bye"), routing_key="bye"), Queue("hello", Exchange("hello"), routing_key="hello"), diff --git a/docker-compose.yml b/docker-compose.yml index b0374b0..7c6d3c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,17 +1,6 @@ version: '3' services: - db: - container_name: db - image: postgres - restart: always - environment: - DB: celery - DB_USER: celery - DB_PASSWORD: celery - ports: - - 5432:5432 - redis: container_name: redis image: redis:latest diff --git a/requirements.txt b/requirements.txt index 0af9500..6834ad4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ python-dotenv==1.0.0 pydantic==2.5.2 pydantic-settings==2.1.0 SQLAlchemy==2.0.23 -psycopg2==2.9.9 \ No newline at end of file +# psycopg2==2.9.9 +celery-redbeat==2.1.1 \ No newline at end of file