From 770000c3eb61bff8f62e49bec77a06f1e9a6ba9e Mon Sep 17 00:00:00 2001 From: thiagotrabach Date: Tue, 12 Sep 2023 15:27:21 -0300 Subject: [PATCH 1/5] initial commit --- pipelines/rj_sms/__init__.py | 1 + pipelines/rj_sms/check_ip/__init__.py | 0 pipelines/rj_sms/check_ip/flows.py | 23 +++++++++++++++++++++++ pipelines/rj_sms/check_ip/tasks.py | 21 +++++++++++++++++++++ pipelines/rj_sms/run.py | 4 ++++ 5 files changed, 49 insertions(+) create mode 100644 pipelines/rj_sms/check_ip/__init__.py create mode 100644 pipelines/rj_sms/check_ip/flows.py create mode 100644 pipelines/rj_sms/check_ip/tasks.py create mode 100644 pipelines/rj_sms/run.py diff --git a/pipelines/rj_sms/__init__.py b/pipelines/rj_sms/__init__.py index e73a968a6..ba06577f2 100644 --- a/pipelines/rj_sms/__init__.py +++ b/pipelines/rj_sms/__init__.py @@ -5,3 +5,4 @@ from pipelines.rj_sms.dump_db_sivep.flows import * from pipelines.rj_sms.pubsub.flows import * +from pipelines.rj_sms.check_ip.flows import * \ No newline at end of file diff --git a/pipelines/rj_sms/check_ip/__init__.py b/pipelines/rj_sms/check_ip/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pipelines/rj_sms/check_ip/flows.py b/pipelines/rj_sms/check_ip/flows.py new file mode 100644 index 000000000..65ec681d1 --- /dev/null +++ b/pipelines/rj_sms/check_ip/flows.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from pipelines.utils.decorators import Flow +from pipelines.constants import constants +from prefect.run_configs import KubernetesRun +from prefect.storage import GCS +from pipelines.rj_sms.check_ip.tasks import get_public_ip + + +with Flow( + name="SMS: Check IP - Verifica ip do cluster", code_owners=["thiago"] +) as check_ip: + + # Start run + download_task = get_public_ip() + + +check_ip.storage = GCS(constants.GCS_FLOWS_BUCKET.value) +check_ip.run_config = KubernetesRun( + image=constants.DOCKER_IMAGE.value, + labels=[ + constants.RJ_SMS_DEV_AGENT_LABEL.value, + ], +) diff --git a/pipelines/rj_sms/check_ip/tasks.py b/pipelines/rj_sms/check_ip/tasks.py new file mode 100644 index 000000000..8a1dc092f --- /dev/null +++ b/pipelines/rj_sms/check_ip/tasks.py @@ -0,0 +1,21 @@ +import requests +from prefect import task +from pipelines.utils.utils import log + + +@task +def get_public_ip(): + try: + # Use a public IP address API to fetch your IP address + response = requests.get('https://api64.ipify.org?format=json') + + if response.status_code == 200: + data = response.json() + log(F"IP: {data['ip']}") + return data['ip'] + else: + log(f"Failed to retrieve IP address. Status Code: {response.status_code}") + except Exception as e: + log(f"An error occurred: {str(e)}") + + return None \ No newline at end of file diff --git a/pipelines/rj_sms/run.py b/pipelines/rj_sms/run.py new file mode 100644 index 000000000..f4410625e --- /dev/null +++ b/pipelines/rj_sms/run.py @@ -0,0 +1,4 @@ +from pipelines.rj_sms.check_ip.flows import check_ip +from pipelines.utils.utils import run_local + +run_local(check_ip) \ No newline at end of file From acf7c9b804647f15a3dbb9f3c87bf812ed925015 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:27:54 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pipelines/rj_sms/__init__.py | 2 +- pipelines/rj_sms/check_ip/flows.py | 1 - pipelines/rj_sms/check_ip/tasks.py | 13 +++++++------ pipelines/rj_sms/run.py | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pipelines/rj_sms/__init__.py b/pipelines/rj_sms/__init__.py index ba06577f2..911924b4f 100644 --- a/pipelines/rj_sms/__init__.py +++ b/pipelines/rj_sms/__init__.py @@ -5,4 +5,4 @@ from pipelines.rj_sms.dump_db_sivep.flows import * from pipelines.rj_sms.pubsub.flows import * -from pipelines.rj_sms.check_ip.flows import * \ No newline at end of file +from pipelines.rj_sms.check_ip.flows import * diff --git a/pipelines/rj_sms/check_ip/flows.py b/pipelines/rj_sms/check_ip/flows.py index 65ec681d1..fb97620a6 100644 --- a/pipelines/rj_sms/check_ip/flows.py +++ b/pipelines/rj_sms/check_ip/flows.py @@ -9,7 +9,6 @@ with Flow( name="SMS: Check IP - Verifica ip do cluster", code_owners=["thiago"] ) as check_ip: - # Start run download_task = get_public_ip() diff --git a/pipelines/rj_sms/check_ip/tasks.py b/pipelines/rj_sms/check_ip/tasks.py index 8a1dc092f..c4f907c61 100644 --- a/pipelines/rj_sms/check_ip/tasks.py +++ b/pipelines/rj_sms/check_ip/tasks.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import requests from prefect import task from pipelines.utils.utils import log @@ -7,15 +8,15 @@ def get_public_ip(): try: # Use a public IP address API to fetch your IP address - response = requests.get('https://api64.ipify.org?format=json') - + response = requests.get("https://api64.ipify.org?format=json") + if response.status_code == 200: data = response.json() - log(F"IP: {data['ip']}") - return data['ip'] + log(f"IP: {data['ip']}") + return data["ip"] else: log(f"Failed to retrieve IP address. Status Code: {response.status_code}") except Exception as e: log(f"An error occurred: {str(e)}") - - return None \ No newline at end of file + + return None diff --git a/pipelines/rj_sms/run.py b/pipelines/rj_sms/run.py index f4410625e..3e008512f 100644 --- a/pipelines/rj_sms/run.py +++ b/pipelines/rj_sms/run.py @@ -1,4 +1,5 @@ +# -*- coding: utf-8 -*- from pipelines.rj_sms.check_ip.flows import check_ip from pipelines.utils.utils import run_local -run_local(check_ip) \ No newline at end of file +run_local(check_ip) From f29ff496b4f5c9d2c7aae2ff665e73dd0e9e7d23 Mon Sep 17 00:00:00 2001 From: thiagotrabach Date: Tue, 12 Sep 2023 15:45:35 -0300 Subject: [PATCH 3/5] remove init --- pipelines/rj_sms/check_ip/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pipelines/rj_sms/check_ip/__init__.py diff --git a/pipelines/rj_sms/check_ip/__init__.py b/pipelines/rj_sms/check_ip/__init__.py deleted file mode 100644 index e69de29bb..000000000 From 5fccc6fe3d217461db56e37e423705a963106c83 Mon Sep 17 00:00:00 2001 From: thiagotrabach Date: Tue, 12 Sep 2023 15:52:02 -0300 Subject: [PATCH 4/5] fix flow --- pipelines/rj_sms/check_ip/flows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/rj_sms/check_ip/flows.py b/pipelines/rj_sms/check_ip/flows.py index fb97620a6..9a662c9b0 100644 --- a/pipelines/rj_sms/check_ip/flows.py +++ b/pipelines/rj_sms/check_ip/flows.py @@ -5,7 +5,7 @@ from prefect.storage import GCS from pipelines.rj_sms.check_ip.tasks import get_public_ip - +@Flow with Flow( name="SMS: Check IP - Verifica ip do cluster", code_owners=["thiago"] ) as check_ip: From 6164a766b24ac788fc862209d5029efa99f57d88 Mon Sep 17 00:00:00 2001 From: thiagotrabach Date: Tue, 12 Sep 2023 16:02:37 -0300 Subject: [PATCH 5/5] wip --- pipelines/rj_sms/check_ip/flows.py | 1 - pipelines/rj_sms/check_ip/tasks.py | 1 - 2 files changed, 2 deletions(-) diff --git a/pipelines/rj_sms/check_ip/flows.py b/pipelines/rj_sms/check_ip/flows.py index 9a662c9b0..ac77bdb6f 100644 --- a/pipelines/rj_sms/check_ip/flows.py +++ b/pipelines/rj_sms/check_ip/flows.py @@ -5,7 +5,6 @@ from prefect.storage import GCS from pipelines.rj_sms.check_ip.tasks import get_public_ip -@Flow with Flow( name="SMS: Check IP - Verifica ip do cluster", code_owners=["thiago"] ) as check_ip: diff --git a/pipelines/rj_sms/check_ip/tasks.py b/pipelines/rj_sms/check_ip/tasks.py index c4f907c61..34e2eac9a 100644 --- a/pipelines/rj_sms/check_ip/tasks.py +++ b/pipelines/rj_sms/check_ip/tasks.py @@ -13,7 +13,6 @@ def get_public_ip(): if response.status_code == 200: data = response.json() log(f"IP: {data['ip']}") - return data["ip"] else: log(f"Failed to retrieve IP address. Status Code: {response.status_code}") except Exception as e: