Skip to content

Commit

Permalink
Use hash for schedule job id (#80)
Browse files Browse the repository at this point in the history
Signed-off-by: Khor Shu Heng <khor.heng@go-jek.com>
  • Loading branch information
khorshuheng committed Jul 27, 2021
1 parent 2278b61 commit 93f1f5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 3 additions & 8 deletions python/feast_spark/pyspark/launchers/k8s/k8s.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import random
import string
import time
Expand Down Expand Up @@ -63,14 +64,8 @@ def _generate_job_id() -> str:


def _generate_scheduled_job_id(project: str, feature_table_name: str) -> str:
scheduled_job_id = f"feast-{project}-{feature_table_name}".replace("_", "-")
k8s_res_name_char_limit = 253

return (
scheduled_job_id
if len(scheduled_job_id) <= k8s_res_name_char_limit
else scheduled_job_id[:k8s_res_name_char_limit]
)
job_hash = hashlib.md5(f"{project}-{feature_table_name}".encode()).hexdigest()
return f"feast-{job_hash}"


def _truncate_label(label: str) -> str:
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/test_job_scheduling.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import uuid

import pytest as pytest
Expand Down Expand Up @@ -36,12 +37,17 @@ def test_schedule_batch_ingestion_jobs(
k8s_api = client.CustomObjectsApi()

def get_scheduled_spark_application():
job_hash = hashlib.md5(
f"{feast_client.project}-{feature_table.name}".encode()
).hexdigest()
resource_name = f"feast-{job_hash}"

return k8s_api.get_namespaced_custom_object(
group="sparkoperator.k8s.io",
version="v1beta2",
namespace=pytestconfig.getoption("k8s_namespace"),
plural="scheduledsparkapplications",
name=f"feast-{feast_client.project}-{feature_table.name}".replace("_", "-"),
name=resource_name,
)

response = get_scheduled_spark_application()
Expand Down

0 comments on commit 93f1f5b

Please sign in to comment.