An HTTP API for the looper run command that works with the pydantic-based command models#441
Merged
simeoncarstens merged 46 commits intopepkit:feature-http-apifrom Feb 8, 2024
Merged
Conversation
Contributor
|
can you put the usage information into a readme? |
6b81058 to
cd5ebcf
Compare
a083b01 to
f92be03
Compare
cd5ebcf to
d71763b
Compare
5c3a47c to
643779c
Compare
1d5d17f to
c21d8ed
Compare
That's because this endpoint will support _all_ commands, and not only `run`.
This allows, together with the hacked, threadable (but _not_ thread-safe) `yacman` version, to run `looper` commands in a non-blocking way.
Everything will probably still work - after all, `logmuse.logger_via_cli()` is called in `cli_looper.py` / `cli_pydantic.py` which also sets up a logger.
Before this commit, the logging stdout we captured will be mixed if we submit several jobs at the same time. This captures outputs for each thread (job) separately. See https://stackoverflow.com/questions/14890997/redirect-stdout-to-a-file-only-for-a-specific-thread. Co-authored-by: Simeon Carstens <simeon.carstens@tweag.io>
This allows us to capture the output of the Bash scripts or commands `looper` executes.
Co-authored-by: Zhihan Zhang <zhihan.zhang@tweag.io>
The module we use to capture console output does not seem to distinguish easily between `stdout` and `stderr`. So we rather use a generic `console_output` field in the job model that subsumes both.
This makes the Swagger documentation show the job schema for that endpoint.
* Apply formatter * Add documentation for `POST` and `GET` requests * Update looper/api/main.py Co-authored-by: Simeon Carstens <simeon.carstens@tweag.io> * Update looper/api/main.py Co-authored-by: Simeon Carstens <simeon.carstens@tweag.io> * Add where to access the API documentation --------- Co-authored-by: Simeon Carstens <simeon.carstens@tweag.io>
4e5090d to
ffefcd1
Compare
looper run command that works with the pydantic-based CLIlooper run command that works with the pydantic-based command models
ffefcd1 to
6619440
Compare
looper run command that works with the pydantic-based command modelslooper run command that works with the pydantic-based command models
donaldcampbelljr
approved these changes
Feb 7, 2024
Contributor
donaldcampbelljr
left a comment
There was a problem hiding this comment.
This looks good. Please proceed with merging #440 into its feature branch and then this PR into its feature branch when you are able.
Collaborator
|
Done 🙂 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Warning
Currently based on #440. Once that is merged, we'll make a new branch,
feature-http-api, that will be based on the then updateddevbranch and targetfeature-http-apiwith this PR. So don't merge just quite yet 🙂This PR introduces a first version of an HTTP API to execute
loopercommands (#433).Changes made:
looper runcommand.enrich_vars_cfg()function inlooper/utils.pymodule to enable execution via both the CLI and the HTTP API.cli_pydantic.pyEndpoints
/(POST): allows users to triggerloopercommands asynchronously . For now, because we only have theruncommand modeled as apydanticmodel, only theruncommand is supported. Returns a unique job ID that can be used in the/statusendpoint.This endpoint accepts a JSON payload with the
runmodel and other top-level parameters such aslooper_config, see the auto-generated documentation onhttp://127.0.0.1:8000/docsand / orlooper/command_models/commands.py./status/<job ID>(GET): retrieve the status / results of a previously started job. Returns a JSON with, notably, a fieldconsole_outputthat contains allstdout/stderrfrom the performedlooperrun, once the job has finished.Usage:
Run the app:
Note
This assumes that all files specified in the arguments are available on the file system of the machine that is running the HTTP API server. Best make sure you use absolute file paths in all
looperYAML configuration files.To test this, you can clone the
hello_looperrepository and then run (for example) the following in a second terminal:This will return a six-letter job ID, say
abc123. Then get the result / output of the run withFor better visualization / readability, you can post-process the output by piping it to
jq(| jq -r .console_output).