-
Notifications
You must be signed in to change notification settings - Fork 0
working on airflow dag #35
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,20 +1,22 @@ | ||
| from email.policy import default | ||
| import os | ||
| from socket import timeout | ||
| from tracemalloc import start | ||
|
Comment on lines
+1
to
+4
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. |
||
| from airflow.sdk import dag, task | ||
| from pendulum import datetime | ||
| from celery import Celery | ||
| from github import Auth, Github, GithubException | ||
| from client import get_data_from_queue | ||
| from datetime import timedelta | ||
| import time | ||
| from airflow.models import Variable | ||
| from worker import app | ||
|
|
||
|
|
||
| app = Celery( | ||
| 'airflow_client', | ||
| broker = os.getenv('CELERY_BROKER_URL'), | ||
| backend = os.getenv('CELERY_BACKEND_URL') | ||
| ) | ||
|
|
||
| # app = Celery( | ||
| # 'airflow_client', | ||
| # broker = os.getenv('CELERY_BROKER_URL'), | ||
| # backend = os.getenv('CELERY_BACKEND_URL') | ||
| # ) | ||
|
|
||
| @dag( | ||
| schedule="@hourly", | ||
|
|
@@ -45,16 +47,19 @@ def send_task_to_celery_worker(**context): | |
| rate_limit = context["ti"].xcom_pull(task_ids="check_rate_limit", key="remaining") | ||
| max_total_api_calls = context["ti"].xcom_pull(task_ids="check_rate_limit", key="total") | ||
|
|
||
| app.send_task("worker.get_github_data", kwargs={"start_in_repo_num": 1000, "batch_size": 500}) | ||
| start_with_repo_number = int(Variable.get("github_repo_number", default_var = "0")) | ||
| start_with_repo_number += 500 | ||
|
|
||
| print("celery_worker") | ||
| app.send_task("worker.get_github_data", kwargs={"start_in_repo_num": start_with_repo_number, "batch_size": 500}) | ||
|
|
||
| Variable.set(key= "github_repo_number", value= str(start_with_repo_number)) | ||
|
Comment on lines
+50
to
+55
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 current logic for determining To fix this, the |
||
| print("celery_worker") | ||
|
|
||
| @task | ||
| def save_data_from_queue(): | ||
|
|
||
| get_data_from_queue() | ||
|
|
||
|
|
||
|
|
||
| check_rate_limit() >> send_task_to_celery_worker() >> save_data_from_queue() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,7 +116,6 @@ def get_github_data(self, start_in_repo_num: int = 0, batch_size: int = 500): | |
| properties=pika.BasicProperties(delivery_mode=2) | ||
| ) | ||
|
|
||
| counter += 1 | ||
| logger.info(github_data_points) | ||
|
|
||
| except Exception as validation_error: | ||
|
|
@@ -127,8 +126,6 @@ def get_github_data(self, start_in_repo_num: int = 0, batch_size: int = 500): | |
| remaining_api_calls = gh.rate_limiting | ||
| remaining = remaining_api_calls[0] | ||
|
|
||
| if counter >= 5: | ||
| break | ||
|
|
||
| if counter >= batch_size: | ||
| logger.info(f"Reached batch size of {batch_size}") | ||
|
|
@@ -152,6 +149,11 @@ def get_github_data(self, start_in_repo_num: int = 0, batch_size: int = 500): | |
| logger.info("Count") | ||
| logger.info(counter) | ||
|
|
||
| counter += 1 | ||
|
|
||
| if counter >= 25: | ||
| break | ||
|
Comment on lines
+154
to
+155
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.
Comment on lines
+154
to
+155
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. |
||
|
|
||
| except Exception as e: | ||
| logger.exception("Error", e) | ||
|
|
||
|
|
||
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.
There are several unused imports in this block:
defaultfromemail.policy(line 1),timeoutfromsocket(line 3), andstartfromtracemalloc(line 4). These should be removed to keep the code clean.