Skip to content

Commit d98d9a7

Browse files
[flyteagent] FileSensor Timeout (Remote Execution Only) Enhancement (#3191)
Signed-off-by: Future-Outlier <[email protected]>
1 parent 479d6de commit d98d9a7

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Diff for: flytekit/sensor/base_sensor.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ def __init__(
6363
annotation = type_hints.get(k, None)
6464
inputs[k] = annotation
6565

66-
if kwargs.get("metadata", None) and timeout:
67-
raise ValueError("You cannot set timeout and metadata at the same time in the sensor")
68-
69-
metadata = TaskMetadata(timeout=timeout)
66+
# Handle metadata and timeout logic
67+
metadata = kwargs.pop("metadata", None)
68+
if metadata is not None and timeout is not None:
69+
if metadata.timeout is not None:
70+
raise ValueError("You cannot set both timeout and metadata parameters at the same time in the sensor")
71+
else:
72+
metadata.timeout = timeout
73+
else:
74+
metadata = TaskMetadata(timeout=timeout) if timeout else TaskMetadata()
7075

7176
super().__init__(
7277
task_type=task_type,

Diff for: tests/flytekit/unit/sensor/test_file_sensor.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,19 @@ def test_agent_executor_timeout_logging():
7979
assert sensor.metadata.timeout == datetime.timedelta(seconds=60)
8080

8181
def test_file_sensor_set_timeout_and_metadata_at_the_same_time():
82+
"""
83+
The test is the combination of the following cases:
84+
1. Set timeout and metadata with timeout at the same time
85+
2. Set timeout and metadata without timeout
86+
3. Set timeout and no metadata
87+
4. Not set timeout and metadata with timeout
88+
"""
89+
8290
timeout = datetime.timedelta(seconds=60)
83-
metadata = TaskMetadata(timeout=timeout)
8491

85-
with pytest.raises(ValueError, match="You cannot set timeout and metadata at the same time in the sensor"):
86-
FileSensor(name="test_sensor", timeout=60, metadata=metadata)
92+
with pytest.raises(ValueError, match="You cannot set both timeout and metadata parameters at the same time in the sensor"):
93+
FileSensor(name="test_sensor", timeout=60, metadata=TaskMetadata(timeout=timeout))
94+
95+
FileSensor(name="test_sensor", timeout=60, metadata=TaskMetadata())
96+
FileSensor(name="test_sensor", timeout=60)
97+
FileSensor(name="test_sensor", metadata=TaskMetadata(timeout=timeout))

0 commit comments

Comments
 (0)