-
Notifications
You must be signed in to change notification settings - Fork 32
✨ dynamic-scheduler can chain operations #8446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
18e3669
added after event manager
992cfc1
added rest of code
8da80c9
added cancellable operation
b48c7e4
revert changes
6ee4e25
fixed test
9039b37
added capability to run operation when one is done
bcf2721
added tests to ensure switching of operations
52b4f7d
Merge remote-tracking branch 'upstream/master' into migrate-dy-schedu…
33f1b6e
event is actually emitted when the previous operation finished
c5201f2
fixed flaky tests
8880e81
Merge remote-tracking branch 'upstream/master' into migrate-dy-schedu…
83448f4
mypy + pylint
e44c0d7
typos
0bf48e7
typos
d617187
fixed broken functionality
29a947b
Merge remote-tracking branch 'upstream/master' into migrate-dy-schedu…
e1c4201
pylint
8ef6313
removed commented commander
38dac25
typo
93b83e6
refactor event scheduler
65b5256
Merge remote-tracking branch 'upstream/master' into migrate-dy-schedu…
e91aead
Merge remote-tracking branch 'upstream/master' into migrate-dy-schedu…
8e6a4f2
added test
7e42181
operation is composed instead of inherited form list
0c72939
renamed create/undo to execute/revert
878bd62
Merge remote-tracking branch 'upstream/master' into migrate-dy-schedu…
b021862
mypy
ca93197
Merge remote-tracking branch 'upstream/master' into migrate-dy-schedu…
c100e56
Merge branch 'master' into migrate-dy-scheduler-6
GitHK a2e528f
address possible flaky
a1338ac
Merge branch 'migrate-dy-scheduler-6' of github.com:GitHK/osparc-simc…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...cheduler/src/simcore_service_dynamic_scheduler/services/generic_scheduler/_event_after.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import logging | ||
|
|
||
| from fastapi import FastAPI | ||
| from servicelib.fastapi.app_state import SingletonInAppStateMixin | ||
| from servicelib.logging_utils import log_context | ||
|
|
||
| from ._core import start_operation | ||
| from ._models import ( | ||
| EventType, | ||
| OperationContext, | ||
| OperationName, | ||
| OperationToStart, | ||
| ScheduleId, | ||
| ) | ||
| from ._operation import OperationRegistry | ||
| from ._store import OperationEventsProxy, Store | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AfterEventManager(SingletonInAppStateMixin): | ||
| """ | ||
| Allows to register an operation to be started after | ||
| another operation ends the CREATED or UNDONE successfully. | ||
| """ | ||
|
|
||
| app_state_name: str = "after_event_manager" | ||
|
|
||
| def __init__(self, app: FastAPI) -> None: | ||
| self.app = app | ||
| self._store = Store.get_from_app_state(app) | ||
|
|
||
| async def register_to_start_after( | ||
| self, | ||
| schedule_id: ScheduleId, | ||
| event_type: EventType, | ||
| *, | ||
| to_start: OperationToStart, | ||
| ) -> None: | ||
| # ensure operation exists | ||
| OperationRegistry.get_operation(to_start.operation_name) | ||
|
|
||
| events_proxy = OperationEventsProxy(self._store, schedule_id, event_type) | ||
| await events_proxy.create_or_update_multiple( | ||
| { | ||
| "initial_context": to_start.initial_context, | ||
| "operation_name": to_start.operation_name, | ||
| } | ||
| ) | ||
| _logger.debug( | ||
| "Registered event_type='%s' to_start='%s' for schedule_id='%s'", | ||
| event_type, | ||
| to_start, | ||
| schedule_id, | ||
| ) | ||
|
|
||
| async def safe_on_event_type( | ||
| self, | ||
| event_type: EventType, | ||
| schedule_id: ScheduleId, | ||
| operation_name: OperationName, | ||
| initial_context: OperationContext, | ||
| ) -> None: | ||
| with log_context( | ||
| _logger, | ||
| logging.DEBUG, | ||
| f"processing {event_type=} for {schedule_id=} {operation_name=} {initial_context=}", | ||
| log_duration=True, | ||
| ): | ||
| await self._on_event_type( | ||
| event_type, schedule_id, operation_name, initial_context | ||
| ) | ||
|
|
||
| async def _on_event_type( | ||
| self, | ||
| event_type: EventType, | ||
| schedule_id: ScheduleId, | ||
| operation_name: OperationName, | ||
| initial_context: OperationContext, | ||
| ) -> None: | ||
| new_schedule_id = await start_operation( | ||
| self.app, operation_name, initial_context | ||
| ) | ||
| _logger.debug( | ||
| "Finished execution of event_type='%s' for schedule_id='%s'. " | ||
| "Started new_schedule_id='%s' from operation_name='%s' with initial_context='%s'", | ||
| event_type, | ||
| schedule_id, | ||
| new_schedule_id, | ||
| operation_name, | ||
| initial_context, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.