Skip to content

Commit

Permalink
Force next color
Browse files Browse the repository at this point in the history
  • Loading branch information
MKCG committed Nov 22, 2023
1 parent cd09415 commit 50763ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
8 changes: 4 additions & 4 deletions DAG-insert-elk-sirene.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
# on_failure_callback=send_notification_failure_tchap,
max_active_runs=1,
) as dag:
# get_colors = PythonOperator(
# task_id="get_colors", provide_context=True, python_callable=get_colors
# )
get_colors = PythonOperator(
task_id="get_colors", provide_context=True, python_callable=get_colors
)

clean_previous_folder = CleanFolderOperator(
task_id="clean_previous_folder",
Expand Down Expand Up @@ -362,7 +362,7 @@
# python_callable=send_notification_success_tchap,
# )

# clean_previous_folder.set_upstream(get_colors)
clean_previous_folder.set_upstream(get_colors)
create_sqlite_database.set_upstream(clean_previous_folder)

create_unite_legale_table.set_upstream(create_sqlite_database)
Expand Down
25 changes: 14 additions & 11 deletions task_functions/get_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@


def get_colors(**kwargs):
try:
with urlopen(COLOR_URL, timeout=5) as url:
data = json.loads(url.read().decode())
next_color = data["NEXT_COLOR"]
current_color = data["CURRENT_COLOR"]
logging.info(f"******************** Color file URL: {COLOR_URL}")
logging.info(f"******************** Next color from file: {next_color}")
kwargs["ti"].xcom_push(key="next_color", value=next_color)
kwargs["ti"].xcom_push(key="current_color", value=current_color)
except BaseException as error:
raise Exception(f"******************** Ouuups Error: {error}")
kwargs["ti"].xcom_push(key="next_color", value="20231122")
kwargs["ti"].xcom_push(key="current_color", value="green")

# try:
# with urlopen(COLOR_URL, timeout=5) as url:
# data = json.loads(url.read().decode())
# next_color = data["NEXT_COLOR"]
# current_color = data["CURRENT_COLOR"]
# logging.info(f"******************** Color file URL: {COLOR_URL}")
# logging.info(f"******************** Next color from file: {next_color}")
# kwargs["ti"].xcom_push(key="next_color", value=next_color)
# kwargs["ti"].xcom_push(key="current_color", value=current_color)
# except BaseException as error:
# raise Exception(f"******************** Ouuups Error: {error}")
2 changes: 2 additions & 0 deletions task_functions/update_color_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@


def update_color_file(**kwargs):
return

next_color = kwargs["ti"].xcom_pull(key="next_color", task_ids="get_colors")
current_color = kwargs["ti"].xcom_pull(key="current_color", task_ids="get_colors")
colors = {"CURRENT_COLOR": next_color, "NEXT_COLOR": current_color}
Expand Down

0 comments on commit 50763ae

Please sign in to comment.