Skip to content

Commit 1ac7baf

Browse files
committed
PR suggestion improvements
1 parent c857173 commit 1ac7baf

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

azure/durable_functions/models/DurableOrchestrationContext.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self,
6464
self._maximum_short_timer_duration = max_short_duration
6565
self._long_timer_interval_duration: datetime.timedelta
6666
if longRunningTimerIntervalDuration is not None:
67-
long_interval_duration = parse_timespan_attrib(longRunningTimerIntervalDuration)
67+
long_interval_duration = datetime.timedelta(seconds=10) # parse_timespan_attrib(longRunningTimerIntervalDuration)
6868
self._long_timer_interval_duration = long_interval_duration
6969
self._custom_status: Any = None
7070
self._new_uuid_counter: int = 0
@@ -80,9 +80,12 @@ def __init__(self,
8080
self._sequence_number = 0
8181
self._replay_schema = ReplaySchema(upperSchemaVersion)
8282
if (upperSchemaVersionNew is not None
83-
and upperSchemaVersionNew > self._replay_schema.value
84-
and upperSchemaVersionNew in ReplaySchema._value2member_map_):
85-
self._replay_schema = ReplaySchema(upperSchemaVersionNew)
83+
and upperSchemaVersionNew > self._replay_schema.value):
84+
valid_schema_values = [enum_member.value for enum_member in ReplaySchema]
85+
if upperSchemaVersionNew in valid_schema_values:
86+
self._replay_schema = ReplaySchema(upperSchemaVersionNew)
87+
else:
88+
self._replay_schema = ReplaySchema(max(valid_schema_values))
8689

8790
self._action_payload_v1: List[List[Action]] = []
8891
self._action_payload_v2: List[Action] = []

azure/durable_functions/models/Task.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ def __init__(self, id, action: CreateTimerAction, orchestration_context):
337337
final_fire_time = action.fire_at
338338
duration_until_fire = final_fire_time - current_time
339339

340-
if duration_until_fire > self.orchestration_context.maximum_timer_length:
341-
next_fire_time = current_time + self.orchestration_context.long_running_timer_duration
340+
if duration_until_fire > orchestration_context.maximum_short_timer_duration:
341+
next_fire_time = current_time + orchestration_context.long_timer_interval_duration
342342
else:
343343
next_fire_time = final_fire_time
344344

@@ -349,8 +349,8 @@ def __init__(self, id, action: CreateTimerAction, orchestration_context):
349349
self.id = id
350350
self.action = action
351351
self.orchestration_context = orchestration_context
352-
self.maximum_timer_length = self.orchestration_context.maximum_timer_length
353-
self.long_running_timer_duration = self.orchestration_context.long_running_timer_duration
352+
self.maximum_short_timer_duration = self.orchestration_context.maximum_short_timer_duration
353+
self.long_timer_interval_duration = self.orchestration_context.long_timer_interval_duration
354354

355355
def is_canceled(self) -> bool:
356356
"""Check if the LongTimer is cancelled.
@@ -408,8 +408,8 @@ def get_next_timer_task(self, final_fire_time: datetime, current_time: datetime)
408408
A TimerTask representing the next interval of the LongTimer
409409
"""
410410
duration_until_fire = final_fire_time - current_time
411-
if duration_until_fire > self.maximum_timer_length:
412-
next_fire_time = current_time + self.long_running_timer_duration
411+
if duration_until_fire > self.maximum_short_timer_duration:
412+
next_fire_time = current_time + self.long_timer_interval_duration
413413
else:
414414
next_fire_time = final_fire_time
415415
return TimerTask(None, CreateTimerAction(next_fire_time))

azure/durable_functions/models/utils/json_utils.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,20 @@ def parse_timespan_attrib(from_str: str) -> datetime.timedelta:
5757
The TimeSpan expressed as a Python datetime.timedelta
5858
5959
"""
60-
expr = r"^(-)?(?:([0-9]*)\.)?([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.([0-9]{7}))?$"
61-
match = re.match(expr, from_str)
60+
match = re.match(r"^(?P<negative>-)?(?:(?P<days>[0-9]*)\.)?"
61+
r"(?P<hours>[0-9]{2}):(?P<minutes>[0-9]{2})"
62+
r":(?P<seconds>[0-9]{2})(?:\.(?P<ticks>[0-9]{7}))?$",
63+
from_str)
6264
if match:
65+
groups = match.groupdict()
6366
span = datetime.timedelta(
64-
days=int(match.group(2) or "0"),
65-
hours=int(match.group(3)),
66-
minutes=int(match.group(4)),
67-
seconds=int(match.group(5)),
68-
microseconds=int(match.group(6) or "0") // 10)
67+
days=int(groups['days'] or "0"),
68+
hours=int(groups['hours']),
69+
minutes=int(groups['minutes']),
70+
seconds=int(groups['seconds']),
71+
microseconds=int(groups['ticks'] or "0") // 10)
6972

70-
if match.group(1):
73+
if groups['negative'] == '-':
7174
span = -span
7275
return span
7376
else:

0 commit comments

Comments
 (0)