diff --git a/pipelines/rj_sms/__init__.py b/pipelines/rj_sms/__init__.py index e73a968a6..911924b4f 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 * diff --git a/pipelines/rj_sms/check_ip/flows.py b/pipelines/rj_sms/check_ip/flows.py new file mode 100644 index 000000000..ac77bdb6f --- /dev/null +++ b/pipelines/rj_sms/check_ip/flows.py @@ -0,0 +1,21 @@ +# -*- 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..34e2eac9a --- /dev/null +++ b/pipelines/rj_sms/check_ip/tasks.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +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']}") + 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 diff --git a/pipelines/rj_sms/run.py b/pipelines/rj_sms/run.py new file mode 100644 index 000000000..3e008512f --- /dev/null +++ b/pipelines/rj_sms/run.py @@ -0,0 +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)