-
Notifications
You must be signed in to change notification settings - Fork 0
created a shared Docker network #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| from airflow.sdk import dag, task | ||
| from pendulum import datetime | ||
| from celery import Celery | ||
| import os | ||
|
|
||
| app = Celery( | ||
| 'airflow_client', | ||
| broker = os.getenv('CELERY_BROKER_URL'), | ||
| backend = os.getenv('CELERY_BACKEND_URL') | ||
| ) | ||
|
|
||
| @dag( | ||
| schedule="@hourly", | ||
| start_date=datetime(2026, 2, 2), | ||
| start_date=datetime(2026, 2, 3), | ||
| description="Run Celery queue with RabbitMQ as the broker \ | ||
| in order to get GitHub data from the GitHub API", | ||
| tags=["celery_queue"], | ||
|
|
@@ -13,7 +21,7 @@ def run_queue(): | |
|
|
||
| @task | ||
| def run_the_queue(): | ||
| print("hello") | ||
| app.send_task("worker.get_github_data", args=[0, 500]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The arguments For example: @dag(
# ... other arguments
params={"start_in_repo_num": 0, "batch_size": 500},
)You would then access these parameters within your task via the task context. |
||
|
|
||
| run_the_queue() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| services: | ||
| api-server: | ||
| networks: | ||
| - etl-shared | ||
| scheduler: | ||
| networks: | ||
| - etl-shared | ||
| triggerer: | ||
| networks: | ||
| - etl-shared | ||
|
|
||
| networks: | ||
| etl-shared: | ||
| external: true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ services: | |
| timeout: 10s | ||
| retries: 5 | ||
| start_period: 60s | ||
| networks: | ||
| - etl-shared | ||
|
|
||
| redis: | ||
| image: redis:7-alpine | ||
|
|
@@ -31,6 +33,8 @@ services: | |
| retries: 5 | ||
| start_period: 30s | ||
| restart: on-failure | ||
| networks: | ||
| - etl-shared | ||
|
Comment on lines
+36
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Redis service is configured without authentication and is being added to an external shared network ( |
||
|
|
||
| celery_worker: | ||
| build: . | ||
|
|
@@ -56,6 +60,8 @@ services: | |
| redis: | ||
| condition: service_healthy | ||
| restart: on-failure | ||
| networks: | ||
| - etl-shared | ||
|
|
||
| flower: | ||
| image: mher/flower | ||
|
|
@@ -69,6 +75,8 @@ services: | |
| condition: service_healthy | ||
| redis: | ||
| condition: service_healthy | ||
| networks: | ||
| - etl-shared | ||
|
|
||
| client: | ||
| build: . | ||
|
|
@@ -83,6 +91,8 @@ services: | |
| condition: service_healthy | ||
| celery_worker: | ||
| condition: service_healthy | ||
| networks: | ||
| - etl-shared | ||
|
|
||
|
|
||
| # airflow-init: | ||
|
|
@@ -130,4 +140,8 @@ services: | |
|
|
||
| volumes: | ||
| rabbitmq_data: | ||
| redis_data: | ||
| redis_data: | ||
|
|
||
| networks: | ||
| etl-shared: | ||
| external: true | ||
|
Comment on lines
+145
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
os.getenvto fetch connection details directly within a DAG is not a recommended practice. It makes the DAG less portable and harder to manage as it creates a tight coupling with the execution environment's environment variables. A more robust and secure approach is to use Airflow Connections. You can store your broker and backend URLs as a Celery connection in the Airflow UI and then retrieve them in your DAG using an Airflow hook. This centralizes connection management and enhances security.