Skip to content
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

Use FastAPI to provide rest endpoints #135

Merged
merged 27 commits into from
May 11, 2023

Conversation

rosesyrett
Copy link
Contributor

resolves #120

The only thing left to do is change the cli commands.

@codecov
Copy link

codecov bot commented Apr 21, 2023

Codecov Report

Merging #135 (a724fab) into main (3cc3d19) will increase coverage by 4.30%.
The diff coverage is 86.61%.

@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
+ Coverage   83.09%   87.39%   +4.30%     
==========================================
  Files          39       40       +1     
  Lines        1035     1079      +44     
==========================================
+ Hits          860      943      +83     
+ Misses        175      136      -39     
Impacted Files Coverage Δ
src/blueapi/__init__.py 100.00% <ø> (ø)
src/blueapi/service/handler.py 69.76% <69.76%> (ø)
src/blueapi/service/main.py 87.87% <87.87%> (ø)
src/blueapi/cli/cli.py 97.40% <100.00%> (+33.46%) ⬆️
src/blueapi/config.py 95.74% <100.00%> (+0.39%) ⬆️
src/blueapi/service/__init__.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/config.py Outdated Show resolved Hide resolved
src/blueapi/cli/amq.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/rest/handler.py Outdated Show resolved Hide resolved
src/blueapi/rest/handler.py Outdated Show resolved Hide resolved
src/blueapi/rest/main.py Outdated Show resolved Hide resolved
src/blueapi/rest/main.py Outdated Show resolved Hide resolved
src/blueapi/worker/reworker.py Outdated Show resolved Hide resolved
@rosesyrett
Copy link
Contributor Author

Just so you know I don't have write access so can't resolve the merge conflicts. Happy for someone else to do it or give me write access (or both?)

Copy link
Collaborator

@callumforrester callumforrester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, needs a bit of back and forth but definitely getting there.

src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/amq.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/rest/handler.py Outdated Show resolved Hide resolved
src/blueapi/rest/handler.py Outdated Show resolved Hide resolved
src/blueapi/rest/handler.py Outdated Show resolved Hide resolved
src/blueapi/rest/main.py Outdated Show resolved Hide resolved
src/blueapi/worker/reworker.py Outdated Show resolved Hide resolved
@rosesyrett
Copy link
Contributor Author

I think I've changed stuff enough now, in response to comments. Please have a look.

I'm aware that #145 is related to this PR, i.e. it should probably get merged first and then the lines changed for this PR will be smaller. Happy to work on this with you @callumforrester

@callumforrester
Copy link
Collaborator

@RAYemelyanova Regarding the merge conflicts, you should have access now, let me know if there are any problems

@rosesyrett rosesyrett mentioned this pull request May 3, 2023
@rosesyrett rosesyrett force-pushed the restify branch 3 times, most recently from 3bb6d6a to ef7f7db Compare May 5, 2023 12:51
Copy link
Collaborator

@callumforrester callumforrester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close, main thing is we can't have a top-level command called run. I also agree that bluesky worker was the wrong choice which is why I renamed it to blueapi worker, but happy to discuss further if you have objections to that.

.devcontainer/Dockerfile Outdated Show resolved Hide resolved
.vscode/launch.json Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/config.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Show resolved Hide resolved
src/blueapi/service/handler.py Show resolved Hide resolved
src/blueapi/service/handler.py Show resolved Hide resolved
src/blueapi/service/main.py Show resolved Hide resolved
tests/service/test_rest_api.py Outdated Show resolved Hide resolved
tests/service/test_rest_api.py Outdated Show resolved Hide resolved
tests/test_cli.py Outdated Show resolved Hide resolved
self.context.with_startup_script(self.config.env.startup_script)

self.worker = RunEngineWorker(self.context)
self.message_bus = StompMessagingTemplate.autoconfigured(self.config.stomp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something needs to handle the stomp connection not being available. At the moment, running without aMQ running prints a stacktrace, then hangs. It'd be good to show a useful error message then exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea; will write something in for that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but think we should sort this out in a separate PR to avoid scope creep.

src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@rosesyrett
Copy link
Contributor Author

just need to write some tests for the handler to increase code coverage

src/blueapi/cli/cli.py Outdated Show resolved Hide resolved
src/blueapi/cli/fake_cli.py Outdated Show resolved Hide resolved
Rose Yemelyanova added 2 commits May 11, 2023 08:52
Co-authored-by: Callum Forrester <[email protected]>
@rosesyrett
Copy link
Contributor Author

This is ready to be merged, but here are a few more ideas for future PRs:

  1. the service/handler.py::Handler should gracefully exit if a stomp connection cannot be established,
  2. Need to deal with correlation ID's
  3. Maybe don't use a global HANDLER, but for this some restructuring might be necessary.

@rosesyrett rosesyrett merged commit 76a4e02 into DiamondLightSource:main May 11, 2023
@rosesyrett rosesyrett deleted the restify branch May 11, 2023 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support commands via REST API
5 participants