-
Notifications
You must be signed in to change notification settings - Fork 79
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
feat: Global events #677
Merged
+146
−61
Merged
feat: Global events #677
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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 |
---|---|---|
|
@@ -209,6 +209,37 @@ async def test_bad_event_handler(self, setup_app_runner) -> None: | |
assert ev_res.status == "ok" | ||
assert not ev_res.payload.result.get("ok") | ||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.usefixtures("setup_app_runner") | ||
async def test_unsafe_event(self, setup_app_runner) -> None: | ||
with setup_app_runner(test_app_dir, "run", load = True) as ar: | ||
await init_app_session(ar, session_id=self.proposed_session_id) | ||
ev_req = EventRequest(type="event", payload=WriterEvent( | ||
type="wf-built-run", | ||
handler="nineninenine", | ||
instancePath=None, | ||
payload=None | ||
)) | ||
ev_res = await ar.dispatch_message(self.proposed_session_id, ev_req) | ||
assert ev_res.status == "ok" | ||
assert not ev_res.payload.result.get("ok") | ||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.usefixtures("setup_app_runner") | ||
async def test_safe_global_event(self, setup_app_runner) -> None: | ||
with setup_app_runner(test_app_dir, "run", load = True) as ar: | ||
await init_app_session(ar, session_id=self.proposed_session_id) | ||
ev_req = EventRequest(type="event", payload=WriterEvent( | ||
type="wf-built-run", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the moment, |
||
isSafe=True, | ||
handler="nineninenine", | ||
instancePath=None, | ||
payload=None | ||
)) | ||
ev_res = await ar.dispatch_message(self.proposed_session_id, ev_req) | ||
assert ev_res.status == "ok" | ||
assert ev_res.payload.result.get("result") == 999 | ||
|
||
@pytest.mark.usefixtures("setup_app_runner") | ||
def test_run_code_edit(self, setup_app_runner) -> None: | ||
with setup_app_runner(test_app_dir, "run") as ar: | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Job Vault will be used to store results of async jobs.
A basic dict-based structure for single-node deployments. There'll be an option to use Redis for bigger deployments (we can then use this same Redis to do other interesting stuff).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one concern. I don't know how to save the result of the job in the job vault.
If I understand correctly the goal is to create an API endpoint for triggering a job decoupled from a user session. WF retrieves it and executes it on an
Event handler
of theAppProcess
In this case, the job vault will serve as memory. When the job is finished, it will allow the user to retrieve the result. It is only used for "synchronous" jobs for which we are interested in the result.
My concern is the job vault is in the primary process, the thread pool that run a job in async in WF is in the secondary process. You can write something into the job vault from the secondary process. I have tried to explain what I have understand in the schema below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that a job is always a single event. We dispatch to
app_runner
, then we get the result and, instead of sending via WebSockets, we save it in theJobVault
. The vault stays completely independent from the internals (AppProcess
,AppRunner
, etc) - it all happens atserve
level.I wrote some working code that I didn't include as part of the PR so that this PR can be focused on foundations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, you rely on
loop.create_task
. That was the part I wasn't sure. Looks ok for me then.