Skip to content

Commit

Permalink
Remove unnecessary control logic and otherwise simplify main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Jul 24, 2024
1 parent c0e27a6 commit 7ec0e72
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions updates_and_signals/safe_message_handlers/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def __init__(self) -> None:
# Protects workflow state from interleaved access
self.nodes_lock = asyncio.Lock()
self.max_history_length: Optional[int] = None
self.sleep_interval_seconds: int = 600

@workflow.signal
async def start_cluster(self) -> None:
Expand Down Expand Up @@ -176,7 +175,6 @@ def init(self, input: ClusterManagerInput) -> None:
self.state = input.state
if input.test_continue_as_new:
self.max_history_length = 120
self.sleep_interval_seconds = 1

def should_continue_as_new(self) -> bool:
# We don't want to continue-as-new if we're in the middle of an update
Expand All @@ -195,24 +193,16 @@ def should_continue_as_new(self) -> bool:
@workflow.run
async def run(self, input: ClusterManagerInput) -> ClusterManagerResult:
self.init(input)
await workflow.wait_condition(lambda: self.state.cluster_started)
while True:
try:
await workflow.wait_condition(
lambda: self.state.cluster_shutdown
or self.should_continue_as_new(),
timeout=timedelta(seconds=self.sleep_interval_seconds),
)
except asyncio.TimeoutError:
pass
if self.state.cluster_shutdown:
break
if self.should_continue_as_new():
workflow.logger.info("Continuing as new")
workflow.continue_as_new(
ClusterManagerInput(
state=self.state,
test_continue_as_new=input.test_continue_as_new,
)
await workflow.wait_condition(
lambda: self.state.cluster_shutdown or self.should_continue_as_new()
)
if self.should_continue_as_new():
workflow.logger.info("Continuing as new")
workflow.continue_as_new(
ClusterManagerInput(
state=self.state,
test_continue_as_new=input.test_continue_as_new,
)
return ClusterManagerResult(len(self.get_assigned_nodes()))
)
else:
return ClusterManagerResult(len(self.get_assigned_nodes()))

0 comments on commit 7ec0e72

Please sign in to comment.