Skip to content

Commit

Permalink
Merge pull request #3 from flyteorg/hash-execution-name
Browse files Browse the repository at this point in the history
hash the execution name
  • Loading branch information
samhita-alla authored Jul 15, 2022
2 parents cd068e2 + 76af117 commit bb5d94e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
17 changes: 8 additions & 9 deletions flyte_provider/operators/flyte.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -210,16 +210,15 @@ 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
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 = (
task_id
+ re.sub(
r"[\W_t]+",
"",
context["dag_run"].run_id.split("__")[-1].lower(),
)[: (20 - len(task_id))]
"a" + hashlib.md5(unhashed_execution_name.encode()).hexdigest()[:19]
)

hook = FlyteHook(
Expand Down
2 changes: 1 addition & 1 deletion tests/hooks/test_flyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class TestFlyteHook(unittest.TestCase):

flyte_conn_id = "flyte_default"
execution_name = "flyt1202203301338565"
execution_name = "a038d0f1339c4e7700c0"
conn_type = "flyte"
host = "localhost"
port = "30081"
Expand Down
2 changes: 1 addition & 1 deletion tests/operators/test_flyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestFlyteOperator(unittest.TestCase):
labels = {"key1": "value1"}
version = "v1"
inputs = {"name": "hello world"}
execution_name = "test1202203301355087"
execution_name = "a038d0f1339c4e7700c0"
oauth2_client = {"client_id": "123", "client_secret": "456"}
secrets = [{"group": "secrets", "key": "123"}]
notifications = [{"phases": [1], "email": {"recipients_email": ["[email protected]"]}}]
Expand Down
2 changes: 1 addition & 1 deletion tests/sensors/test_flyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestFlyteSensor(unittest.TestCase):
port = "30081"
project = "flytesnacks"
domain = "development"
execution_name = "test1202203301355081"
execution_name = "a038d0f1339c4e7700c0"

@classmethod
def get_connection(cls):
Expand Down

0 comments on commit bb5d94e

Please sign in to comment.