From 8c6444c9177f9171f81775ac88f44f442d436788 Mon Sep 17 00:00:00 2001 From: Samhita Alla Date: Fri, 15 Jul 2022 19:10:50 +0530 Subject: [PATCH 1/2] hash the execution name Signed-off-by: Samhita Alla --- flyte_provider/operators/flyte.py | 21 ++++++++++----------- tests/hooks/test_flyte.py | 2 +- tests/operators/test_flyte.py | 2 +- tests/sensors/test_flyte.py | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/flyte_provider/operators/flyte.py b/flyte_provider/operators/flyte.py index cbcb061..e026f94 100644 --- a/flyte_provider/operators/flyte.py +++ b/flyte_provider/operators/flyte.py @@ -1,5 +1,5 @@ +import hashlib import inspect -import re from dataclasses import fields from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union @@ -210,18 +210,17 @@ def execute(self, context: "Context") -> str: """Trigger an execution.""" # create a deterministic execution name - task_id = re.sub(r"[\W_]+", "", context["task"].task_id)[:4] + str( - context["task_instance"].try_number - ) - self.execution_name = ( - task_id - + re.sub( - r"[\W_t]+", - "", - context["dag_run"].run_id.split("__")[-1].lower(), - )[: (20 - len(task_id))] + unhashed_execution_name = ( + context["task"].dag_id + + context["task"].task_id + + context["dag_run"].run_id + + str(context["task_instance"].try_number) ) + self.execution_name = hashlib.md5(unhashed_execution_name.encode()).hexdigest()[ + :20 + ] + hook = FlyteHook( flyte_conn_id=self.flyte_conn_id, project=self.project, domain=self.domain ) diff --git a/tests/hooks/test_flyte.py b/tests/hooks/test_flyte.py index dbdbf27..8e0b106 100644 --- a/tests/hooks/test_flyte.py +++ b/tests/hooks/test_flyte.py @@ -14,7 +14,7 @@ class TestFlyteHook(unittest.TestCase): flyte_conn_id = "flyte_default" - execution_name = "flyt1202203301338565" + execution_name = "038d0f1339c4e7700c0a" conn_type = "flyte" host = "localhost" port = "30081" diff --git a/tests/operators/test_flyte.py b/tests/operators/test_flyte.py index d4493bb..56c666f 100644 --- a/tests/operators/test_flyte.py +++ b/tests/operators/test_flyte.py @@ -25,7 +25,7 @@ class TestFlyteOperator(unittest.TestCase): labels = {"key1": "value1"} version = "v1" inputs = {"name": "hello world"} - execution_name = "test1202203301355087" + execution_name = "038d0f1339c4e7700c0a" oauth2_client = {"client_id": "123", "client_secret": "456"} secrets = [{"group": "secrets", "key": "123"}] notifications = [{"phases": [1], "email": {"recipients_email": ["abc@flyte.org"]}}] diff --git a/tests/sensors/test_flyte.py b/tests/sensors/test_flyte.py index 3874a8a..1d6b158 100644 --- a/tests/sensors/test_flyte.py +++ b/tests/sensors/test_flyte.py @@ -21,7 +21,7 @@ class TestFlyteSensor(unittest.TestCase): port = "30081" project = "flytesnacks" domain = "development" - execution_name = "test1202203301355081" + execution_name = "038d0f1339c4e7700c0a" @classmethod def get_connection(cls): From 76af117e7184d2dfeb7fbd00a7ba1c69e299fdae Mon Sep 17 00:00:00 2001 From: Samhita Alla Date: Fri, 15 Jul 2022 19:29:34 +0530 Subject: [PATCH 2/2] first character needs to be a string Signed-off-by: Samhita Alla --- flyte_provider/operators/flyte.py | 6 +++--- tests/hooks/test_flyte.py | 2 +- tests/operators/test_flyte.py | 2 +- tests/sensors/test_flyte.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flyte_provider/operators/flyte.py b/flyte_provider/operators/flyte.py index e026f94..e4e8609 100644 --- a/flyte_provider/operators/flyte.py +++ b/flyte_provider/operators/flyte.py @@ -217,9 +217,9 @@ def execute(self, context: "Context") -> str: + str(context["task_instance"].try_number) ) - self.execution_name = hashlib.md5(unhashed_execution_name.encode()).hexdigest()[ - :20 - ] + self.execution_name = ( + "a" + hashlib.md5(unhashed_execution_name.encode()).hexdigest()[:19] + ) hook = FlyteHook( flyte_conn_id=self.flyte_conn_id, project=self.project, domain=self.domain diff --git a/tests/hooks/test_flyte.py b/tests/hooks/test_flyte.py index 8e0b106..8d9d236 100644 --- a/tests/hooks/test_flyte.py +++ b/tests/hooks/test_flyte.py @@ -14,7 +14,7 @@ class TestFlyteHook(unittest.TestCase): flyte_conn_id = "flyte_default" - execution_name = "038d0f1339c4e7700c0a" + execution_name = "a038d0f1339c4e7700c0" conn_type = "flyte" host = "localhost" port = "30081" diff --git a/tests/operators/test_flyte.py b/tests/operators/test_flyte.py index 56c666f..fcafd97 100644 --- a/tests/operators/test_flyte.py +++ b/tests/operators/test_flyte.py @@ -25,7 +25,7 @@ class TestFlyteOperator(unittest.TestCase): labels = {"key1": "value1"} version = "v1" inputs = {"name": "hello world"} - execution_name = "038d0f1339c4e7700c0a" + execution_name = "a038d0f1339c4e7700c0" oauth2_client = {"client_id": "123", "client_secret": "456"} secrets = [{"group": "secrets", "key": "123"}] notifications = [{"phases": [1], "email": {"recipients_email": ["abc@flyte.org"]}}] diff --git a/tests/sensors/test_flyte.py b/tests/sensors/test_flyte.py index 1d6b158..4e973ce 100644 --- a/tests/sensors/test_flyte.py +++ b/tests/sensors/test_flyte.py @@ -21,7 +21,7 @@ class TestFlyteSensor(unittest.TestCase): port = "30081" project = "flytesnacks" domain = "development" - execution_name = "038d0f1339c4e7700c0a" + execution_name = "a038d0f1339c4e7700c0" @classmethod def get_connection(cls):