Refactor _run_app into composable functions #3269
Open
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.
Describe your changes
This PR refactors the monolithic
_run_appfunction into reusable components. The motivation is to decouple output management from core app lifecycle operations, to allow custom output implementations._run_appinto three parts:_run_app_init, which creates theRunningApp_run_app_create, which calls_create_all_objectsand_publish_app_disconnect_on_error, which encapsulates error handlingOutputManagerfrom_run_appOutputManagerIt's hard to tell from the patch, but the core of the function is now this:
Next steps, to allow custom output management:
_App._logs()public, and have it include metadata (such as the file descriptor and task state).OutputManagerfrom_run_app, by either:_run_app_init,_disconnect_on_error, and_run_app_createpublic, so users can compose their ownrun_appvariant, orOutputManagerto use thoseUnlike the current
App.run()context manager, which doesn't yield until the containers have been build, this would allow the user to start tailing logs as soon as theRunningApphas been created.Checklists
Compatibility checklist
No protobuf changes.
Release checklist
If you intend for this commit to trigger a full release to PyPI, please ensure that the following steps have been taken:
modal_version/__init__.py) has been updated with the next logical versionChangelog