-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3470497
commit 7f4754f
Showing
5 changed files
with
102 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import sys | ||
from functools import partial | ||
from datetime import datetime, timedelta | ||
|
||
from airflow.decorators import dag, task_group, task | ||
from airflow.providers.postgres.hooks.postgres import PostgresHook | ||
from airflow.models import Variable | ||
|
||
DAG_NAME = 'rodars_pull' | ||
DAG_OWNERS = Variable.get('dag_owners', deserialize_json=True).get(DAG_NAME, ['Unknown']) | ||
|
||
repo_path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) | ||
sys.path.insert(0, repo_path) | ||
|
||
from events.construction.itsc_issues_functions import fetch_and_insert_data | ||
from dags.dag_functions import task_fail_slack_alert, get_readme_docmd | ||
from dags.custom_operators import SQLCheckOperatorWithReturnValue | ||
|
||
README_PATH = os.path.join(repo_path, 'events/construction/readme.md') | ||
DOC_MD = get_readme_docmd(README_PATH, DAG_NAME) | ||
|
||
default_args = { | ||
'owner': ','.join(DAG_OWNERS), | ||
'depends_on_past': False, | ||
'start_date': datetime(2024, 11, 27), | ||
'email_on_failure': False, | ||
'email_on_retry': False, | ||
'retries': 1, | ||
'retry_delay': timedelta(minutes=5), | ||
'retry_exponential_backoff': True, #Allow for progressive longer waits between retries | ||
'on_failure_callback': partial(task_fail_slack_alert, use_proxy = True), | ||
'catchup': True, | ||
} | ||
|
||
@dag( | ||
dag_id=DAG_NAME, | ||
default_args=default_args, | ||
max_active_runs=1, | ||
template_searchpath=[ | ||
os.path.join(repo_path,'events/construction/sql') | ||
], | ||
doc_md=DOC_MD, | ||
tags=['rodars', 'pull', 'itsc_central'], | ||
schedule='0 4 * * *' #daily at 4am | ||
) | ||
|
||
def rodars_dag(): | ||
@task | ||
def pull_rodars(ds = None): | ||
"Get RODARS data from ITSC and insert into RDS `vds.vdsconfig`" | ||
itsc_bot = PostgresHook('itsc_postgres') | ||
vds_bot = PostgresHook('vds_bot') | ||
fetch_and_insert_data(select_conn=itsc_bot, insert_conn=vds_bot, start_date=ds) | ||
|
||
#add a delete task to remove outdated revisions? | ||
|
||
pull_rodars() | ||
|
||
rodars_dag() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Introduction | ||
|
||
## RODARS DAG | ||
|
||
<!-- rodars_pull_doc_md --> | ||
|
||
- `pull_rodars`: pulls RODARS issue data from ITSC and inserts into RDS. | ||
|
||
<!-- rodars_pull_doc_md --> |
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,18 @@ | ||
--WIP. May need to delete outdated versions of each issue. | ||
|
||
WITH newest_timestamps AS ( | ||
SELECT DISTINCT ON (divisionid, issueid) | ||
divisionid, | ||
issueid, | ||
timestamputc | ||
FROM gwolofs.itsc_issues | ||
ORDER BY | ||
divisionid, | ||
issueid, | ||
timestamputc DESC | ||
) | ||
|
||
SELECT * | ||
FROM gwolofs.itsc_issues | ||
LEFT JOIN newest_timestamps USING (divisionid, issueid, timestamputc) | ||
WHERE newest_timestamps.timestamputc IS NULL |
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