-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'djeck1432:main' into test/dbconnector
- Loading branch information
Showing
10 changed files
with
241 additions
and
7 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
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
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
Empty file.
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,46 @@ | ||
""" | ||
This module configures the Celery application for the project. | ||
It sets up the Celery instance using Redis as both the message broker | ||
and result backend. The Redis connection details (host and port) are | ||
loaded from environment variables using the `dotenv` library. | ||
Additionally, this module defines a scheduled task configuration that | ||
periodically executes scheduled tasks. | ||
Key Components: | ||
- Loads environment variables using `load_dotenv`. | ||
- Configures Redis connection settings for Celery. | ||
- Defines a Celery beat schedule for recurring tasks. | ||
Usage: | ||
- The Celery app can be imported and used in other parts of the application | ||
to execute tasks or manage workers. | ||
""" | ||
|
||
import os | ||
|
||
from celery import Celery | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
# Redis credentials | ||
REDIS_HOST = os.environ.get("REDIS_HOST", "") | ||
REDIS_PORT = os.environ.get("REDIS_PORT", 6379) | ||
|
||
app = Celery( | ||
main="spotnet", | ||
broker=f"redis://{REDIS_HOST}:{REDIS_PORT}/0", | ||
backend=f"redis://{REDIS_HOST}:{REDIS_PORT}/0", | ||
) | ||
|
||
app.conf.beat_schedule = { | ||
"test-celery-and-redis": { | ||
"task": "test_task", | ||
"schedule": 10, | ||
}, | ||
} | ||
|
||
from .tasks import test_task |
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,26 @@ | ||
""" | ||
This module contains Celery tasks for the application. | ||
It imports the logging module to facilitate logging operations and the | ||
Celery app instance from the `celery_config` module. | ||
Tasks: | ||
- test_task: A simple test task that logs a confirmation message. | ||
""" | ||
|
||
import logging | ||
|
||
from .celery_config import app | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
@app.task(name="test_task") | ||
def test_task() -> None: | ||
""" | ||
A task cybled to test that all is working as expected. | ||
:return: None | ||
""" | ||
# TODO: remove on production | ||
logger.info("Running test_task. All is working as expected.") |
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