Skip to content

Commit 1ed132b

Browse files
author
Andrei Neagu
committed
renamed revert to undo
1 parent ae1f05a commit 1ed132b

File tree

12 files changed

+190
-187
lines changed

12 files changed

+190
-187
lines changed

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/generic_scheduler/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from ._core import (
22
cancel_operation,
3-
restart_operation_step_stuck_during_revert,
3+
restart_operation_step_stuck_during_undo,
44
restart_operation_step_stuck_in_manual_intervention_during_create,
55
start_operation,
66
)
@@ -39,7 +39,7 @@
3939
"ParallelStepGroup",
4040
"ProvidedOperationContext",
4141
"RequiredOperationContext",
42-
"restart_operation_step_stuck_during_revert",
42+
"restart_operation_step_stuck_during_undo",
4343
"restart_operation_step_stuck_in_manual_intervention_during_create",
4444
"ScheduleId",
4545
"SingleStepGroup",

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/generic_scheduler/_core.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ async def start_operation(
117117

118118
async def cancel_operation(self, schedule_id: ScheduleId) -> None:
119119
"""
120-
Sets the operation to revert form the point in which it arrived in:
121-
- when is_creating=True: cancels all steps & moves operation to revert
122-
- when is_creating=False: does nothing, since revert is already running
120+
Sets the operation to undo form the point in which it arrived in:
121+
- when is_creating=True: cancels all steps & moves operation to undo
122+
- when is_creating=False: does nothing, since undo is already running
123123
124124
# NOTE: SEE `_on_schedule_event` for more details
125125
"""
@@ -131,7 +131,7 @@ async def cancel_operation(self, schedule_id: ScheduleId) -> None:
131131

132132
if is_creating is False:
133133
_logger.warning(
134-
"Cannot cancel steps for schedule_id='%s' since REVERT is running",
134+
"Cannot cancel steps for schedule_id='%s' since UNDO is running",
135135
schedule_id,
136136
)
137137
return
@@ -270,7 +270,7 @@ async def restart_operation_step_stuck_in_error(
270270
step_name,
271271
operation_name,
272272
schedule_id,
273-
"manual intervention" if in_manual_intervention else "error in revert",
273+
"manual intervention" if in_manual_intervention else "error in undo",
274274
)
275275
# restart only this step
276276
await start_and_mark_as_started(
@@ -303,24 +303,24 @@ async def _on_schedule_event(self, schedule_id: ScheduleId) -> None:
303303
- `CEREATEING`: default mode when starting an operation
304304
- runs the `create()` of each step in each group (`first` -> `last` group)
305305
- when done, it removes all operation data
306-
- `REVERTING`: revert the actions of `create()` in reverse order with respect to CREATING
307-
- runs the `revert()` of each step in each group (`current` -> `first` group)
306+
- `UNDOING`: undo the actions of `create()` in reverse order with respect to CREATING
307+
- runs the `undo()` of each step in each group (`current` -> `first` group)
308308
- when done, it removes all operation data
309309
- `REPEATING`: repeats the `create()` of all steps in a group
310310
- waits and runs the `create()` of all the steps in last group in the operation
311311
- never completes, unless operation is cancelled
312312
313313
NOTE: `REPEATING` is triggered by setting `BaseStepGroup(repeat_steps=True)` during definition
314314
of an `operation`.
315-
NOTE: `REVERTING` is triggered by calling `cancel_operation()` or when a step finishes with
315+
NOTE: `UNDOING` is triggered by calling `cancel_operation()` or when a step finishes with
316316
status `FAILED` or `CANCELLED` (except in manual intervention).
317317
318318
There are 3 reasons why an operation will hang:
319319
- MANUAL_INTERVENTION: step failed during `create()` and flagged for manual intervention
320320
-> requires support intervention
321-
- STEP_ISSUE: a step failed during `revert()` due to an error in the step's revert code
321+
- STEP_ISSUE: a step failed during `undo()` due to an error in the step's undo code
322322
-> unexpected behviour / requires developer intervention
323-
- FRAMEWORK_ISSUE: a step failed during `revert()` because it was cancelled
323+
- FRAMEWORK_ISSUE: a step failed during `undo()` because it was cancelled
324324
-> unexpected behviour / requires developer intervention
325325
326326
NOTE: only MANUAL_INTERVENTION is an allowed to happen all other failuires are to be treated
@@ -398,8 +398,8 @@ async def _on_schedule_event(self, schedule_id: ScheduleId) -> None:
398398
)
399399

400400
else:
401-
with log_context(_logger, logging.DEBUG, f"REVERTING {base_message}"):
402-
await self._advance_as_reverting(
401+
with log_context(_logger, logging.DEBUG, f"UNDOING {base_message}"):
402+
await self._advance_as_undoing(
403403
steps_statuses,
404404
schedule_data_proxy,
405405
schedule_id,
@@ -419,15 +419,15 @@ async def _advance_as_repeating(
419419
) -> None:
420420
# REPEATING logic:
421421
# 1) sleep before repeating
422-
# 2) if any of the repeating steps was cancelled -> move to revert
422+
# 2) if any of the repeating steps was cancelled -> move to undo
423423
# 3) -> restart all steps in the group
424424

425425
step_proxies: Iterable[StepStoreProxy] = group_step_proxies.values()
426426

427427
# 1) sleep before repeating
428428
await asyncio.sleep(current_step_group.wait_before_repeat.total_seconds())
429429

430-
# 2) if any of the repeating steps was cancelled -> move to revert
430+
# 2) if any of the repeating steps was cancelled -> move to undo
431431

432432
# since some time passed, query all steps statuses again,
433433
# a cancellation request might have been requested
@@ -467,7 +467,7 @@ async def _advance_as_creating(
467467
# - 1a) -> move to next group
468468
# - 1b) if reached the end of the CREATE operation -> remove all created data
469469
# 2) if manual intervention is required -> do nothing else
470-
# 3) if any step in CANCELLED or FAILED (and not in manual intervention) -> move to revert
470+
# 3) if any step in CANCELLED or FAILED (and not in manual intervention) -> move to undo
471471

472472
# 1) if all steps in group in SUUCESS
473473
if all(status == StepStatus.SUCCESS for status in steps_statuses.values()):
@@ -522,15 +522,15 @@ async def _advance_as_creating(
522522
)
523523
return
524524

525-
# 3) if any step in CANCELLED or FAILED (and not in manual intervention) -> move to revert
525+
# 3) if any step in CANCELLED or FAILED (and not in manual intervention) -> move to undo
526526
if any(
527527
s in {StepStatus.FAILED, StepStatus.CANCELLED}
528528
for s in steps_statuses.values()
529529
):
530530
with log_context(
531531
_logger,
532532
logging.DEBUG,
533-
f"{operation_name=} was not successfull: {steps_statuses=}, moving to revert",
533+
f"{operation_name=} was not successfull: {steps_statuses=}, moving to undo",
534534
):
535535
await schedule_data_proxy.create_or_update("is_creating", value=False)
536536
await enqueue_schedule_event(self.app, schedule_id)
@@ -540,7 +540,7 @@ async def _advance_as_creating(
540540
direction="creation", steps_statuses=steps_statuses, schedule_id=schedule_id
541541
)
542542

543-
async def _advance_as_reverting(
543+
async def _advance_as_undoing(
544544
self,
545545
steps_statuses: dict[StepName, StepStatus],
546546
schedule_data_proxy: ScheduleDataStoreProxy,
@@ -549,9 +549,9 @@ async def _advance_as_reverting(
549549
group_index: NonNegativeInt,
550550
current_step_group: BaseStepGroup,
551551
) -> None:
552-
# REVERT logic:
552+
# UNDO logic:
553553
# 1) if all steps in group in SUCCESS
554-
# - 1a) if reached the end of the REVERT operation -> remove all created data
554+
# - 1a) if reached the end of the UNDO operation -> remove all created data
555555
# - 1b) -> move to previous group
556556
# 2) it is unexpected to have a FAILED step -> do nothing else
557557
# 3) it is unexpected to have a CANCELLED step -> do nothing else
@@ -561,7 +561,7 @@ async def _advance_as_reverting(
561561
previous_group_index = group_index - 1
562562
if previous_group_index < 0:
563563

564-
# 1a) if reached the end of the REVERT operation -> remove all created data
564+
# 1a) if reached the end of the UNDO operation -> remove all created data
565565
await cleanup_after_finishing(
566566
self._store, schedule_id=schedule_id, is_creating=False
567567
)
@@ -598,7 +598,7 @@ async def _advance_as_reverting(
598598
for step_name, traceback in error_tracebacks
599599
)
600600
message = (
601-
f"Operation 'revert' for schedule_id='{schedule_id}' failed for steps: "
601+
f"Operation 'undo' for schedule_id='{schedule_id}' failed for steps: "
602602
f"'{failed_step_names}'. Step code should never fail during destruction, "
603603
f"please report to developers:\n{formatted_tracebacks}"
604604
)
@@ -613,7 +613,7 @@ async def _advance_as_reverting(
613613
n for n, s in steps_statuses.items() if s == StepStatus.CANCELLED
614614
]:
615615
message = (
616-
f"Operation 'revert' for schedule_id='{schedule_id}' was cancelled for steps: "
616+
f"Operation 'undo' for schedule_id='{schedule_id}' was cancelled for steps: "
617617
f"{cancelled_step_names}. This should not happen, and should be addressed."
618618
)
619619
_logger.error(message)
@@ -626,7 +626,7 @@ async def _advance_as_reverting(
626626
return
627627

628628
raise UnexpectedStepHandlingError(
629-
direction="revert", steps_statuses=steps_statuses, schedule_id=schedule_id
629+
direction="undo", steps_statuses=steps_statuses, schedule_id=schedule_id
630630
)
631631

632632

@@ -642,10 +642,10 @@ async def start_operation(
642642

643643
async def cancel_operation(app: FastAPI, schedule_id: ScheduleId) -> None:
644644
"""
645-
Unstruct scheduler to revert all steps completed until
645+
Unstruct scheduler to undo all steps completed until
646646
now for the running operation.
647647
648-
`reverting` refers to the act of undoing the effects of a step
648+
`undoing` refers to the act of undoing the effects of a step
649649
that has already been completed (eg: remove a created network)
650650
"""
651651
await Core.get_from_app_state(app).cancel_operation(schedule_id)
@@ -667,14 +667,14 @@ async def restart_operation_step_stuck_in_manual_intervention_during_create(
667667
)
668668

669669

670-
async def restart_operation_step_stuck_during_revert(
670+
async def restart_operation_step_stuck_during_undo(
671671
app: FastAPI, schedule_id: ScheduleId, step_name: StepName
672672
) -> None:
673673
"""
674-
Restarts a `stuck step` while the operation is being reverted
674+
Restarts a `stuck step` while the operation is being undone
675675
676676
`stuck step` is a step that has failed and exhausted all retries
677-
`reverting` refers to the act of undoing the effects of a step
677+
`undoing` refers to the act of undoing the effects of a step
678678
that has already been completed (eg: remove a created network)
679679
"""
680680
await Core.get_from_app_state(app).restart_operation_step_stuck_in_error(

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/generic_scheduler/_core_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async def cleanup_after_finishing(
202202
) -> None:
203203
removal_proxy = OperationRemovalProxy(store=store, schedule_id=schedule_id)
204204
await removal_proxy.delete()
205-
verb = "COMPLETED" if is_creating else "REVERTED"
205+
verb = "COMPLETED" if is_creating else "UNDONE"
206206
_logger.debug("Operation for schedule_id='%s' %s successfully", verb, schedule_id)
207207

208208

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/generic_scheduler/_deferred_runner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def get_retries(cls, context: DeferredContext) -> int:
143143
return (
144144
await step.get_create_retries(context)
145145
if is_creating
146-
else await step.get_revert_retries(context)
146+
else await step.get_undo_retries(context)
147147
)
148148

149149
@classmethod
@@ -153,7 +153,7 @@ async def get_timeout(cls, context: DeferredContext) -> timedelta:
153153
return (
154154
await step.get_create_wait_between_attempts(context)
155155
if is_creating
156-
else await step.get_revert_wait_between_attempts(context)
156+
else await step.get_undo_wait_between_attempts(context)
157157
)
158158

159159
@classmethod
@@ -190,16 +190,16 @@ async def run(cls, context: DeferredContext) -> None:
190190
)
191191
else:
192192
required_context = await operation_context_proxy.read(
193-
*step.get_revert_requires_context_keys()
193+
*step.get_undo_requires_context_keys()
194194
)
195195
_raise_if_any_context_value_is_none(required_context)
196196

197-
step_provided_operation_context = await step.revert(app, required_context)
197+
step_provided_operation_context = await step.undo(app, required_context)
198198
provided_operation_context = step_provided_operation_context or {}
199-
revert_provides_keys = step.get_revert_provides_context_keys()
199+
undo_provides_keys = step.get_undo_provides_context_keys()
200200

201201
_raise_if_provided_context_keys_are_missing_or_none(
202-
provided_operation_context, revert_provides_keys
202+
provided_operation_context, undo_provides_keys
203203
)
204204

205205
await operation_context_proxy.create_or_update(provided_operation_context)

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/generic_scheduler/_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
# contains all inputs and outpus of each step in the operation
1717
OperationContext: TypeAlias = dict[str, Any]
18-
# the inputs of `create` or `revert` of a step
18+
# the inputs of `create` or `undo` of a step
1919
RequiredOperationContext: TypeAlias = dict[str, Any]
20-
# the outputs of `create` or `revert` of a step
20+
# the outputs of `create` or `undo` of a step
2121
ProvidedOperationContext: TypeAlias = dict[str, Any]
2222

2323

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/generic_scheduler/_operation.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,39 +85,39 @@ def wait_for_manual_intervention(cls) -> bool:
8585
"""
8686
return _DEFAULT_WAIT_FOR_MANUAL_INTERVENTION
8787

88-
### REVERT
88+
### UNDO
8989

9090
@classmethod
91-
async def revert(
91+
async def undo(
9292
cls, app: FastAPI, required_context: RequiredOperationContext
9393
) -> ProvidedOperationContext | None:
9494
"""
9595
[optional] handler responsible for cleanup of resources created above.
9696
NOTE: Ensure this is successful if:
9797
- `create` is not executed
9898
- `create` is executed partially
99-
- `revert` is called multiple times
99+
- `undo` is called multiple times
100100
"""
101101
_ = required_context
102102
_ = app
103103
return {}
104104

105105
@classmethod
106-
def get_revert_requires_context_keys(cls) -> set[str]:
106+
def get_undo_requires_context_keys(cls) -> set[str]:
107107
"""
108-
[optional] keys that must be present in the OperationContext when REVERT is called
108+
[optional] keys that must be present in the OperationContext when UNDO is called
109109
"""
110110
return set()
111111

112112
@classmethod
113-
def get_revert_provides_context_keys(cls) -> set[str]:
113+
def get_undo_provides_context_keys(cls) -> set[str]:
114114
"""
115-
[optional] keys that will be added to the OperationContext when REVERT is successful
115+
[optional] keys that will be added to the OperationContext when UNDO is successful
116116
"""
117117
return set()
118118

119119
@classmethod
120-
async def get_revert_retries(cls, context: DeferredContext) -> int:
120+
async def get_undo_retries(cls, context: DeferredContext) -> int:
121121
"""
122122
[optional] amount of retires in case of failure
123123
HINT: you can use `get_operation_context_proxy()`, `get_step_group_proxy(context)`
@@ -127,7 +127,7 @@ async def get_revert_retries(cls, context: DeferredContext) -> int:
127127
return _DEFAULT_STEP_RETRIES
128128

129129
@classmethod
130-
async def get_revert_wait_between_attempts(
130+
async def get_undo_wait_between_attempts(
131131
cls, context: DeferredContext
132132
) -> timedelta:
133133
"""
@@ -240,7 +240,7 @@ def _has_abstract_methods(cls: type[object]) -> bool:
240240
def _validate_operation(operation: Operation) -> dict[StepName, type[BaseStep]]:
241241
detected_steps_names: dict[StepName, type[BaseStep]] = {}
242242
create_provided_keys: set[str] = set()
243-
revert_provided_keys: set[str] = set()
243+
undo_provided_keys: set[str] = set()
244244

245245
for k, step_group in enumerate(operation):
246246
if (
@@ -278,14 +278,14 @@ def _validate_operation(operation: Operation) -> dict[StepName, type[BaseStep]]:
278278
)
279279
raise ValueError(msg)
280280
create_provided_keys.add(key)
281-
for key in step.get_revert_provides_context_keys():
282-
if key in revert_provided_keys:
281+
for key in step.get_undo_provides_context_keys():
282+
if key in undo_provided_keys:
283283
msg = (
284284
f"Step {step_name=} provides already provided {key=} in "
285-
f"{step.get_revert_provides_context_keys.__name__}()"
285+
f"{step.get_undo_provides_context_keys.__name__}()"
286286
)
287287
raise ValueError(msg)
288-
revert_provided_keys.add(key)
288+
undo_provided_keys.add(key)
289289

290290
if (
291291
step_group.repeat_steps is True
@@ -310,7 +310,7 @@ def get_operation_provided_context_keys(operation: Operation) -> set[str]:
310310
for step_group in operation:
311311
for step in step_group.get_step_subgroup_to_run():
312312
provided_keys.update(step.get_create_provides_context_keys())
313-
provided_keys.update(step.get_revert_provides_context_keys())
313+
provided_keys.update(step.get_undo_provides_context_keys())
314314

315315
return provided_keys
316316

0 commit comments

Comments
 (0)