-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
fix: factorizing code #322
Conversation
✅ Deploy Preview for robyn canceled.
|
Hey @AntoineRR 👋 Thanks for your PR. I didn't have much time to review your PR over the past few days. I will try reviewing it tomorrow. Apologies for the delay. 😄 |
No worries, take as much time as you need ^^ |
robyn/processpool.py
Outdated
server.add_route( | ||
route_type, endpoint, handler, is_async, number_of_params, const | ||
) | ||
route_type, endpoint, function, const = route |
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.
If we are refactoring this code, can we please rename the const
variable to is_const
or is_const_function
?
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.
Makes sense, I changed it to is_const
where it is relevant.
route_type, endpoint, function = route | ||
server.add_middleware_route(route_type, endpoint, function) |
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.
Also, I love how the routes and the functions are kept segregated ✨
pub struct Request { | ||
pub queries: HashMap<String, String>, | ||
pub headers: HashMap<String, String>, | ||
pub method: Method, | ||
pub params: HashMap<String, String>, | ||
pub body: Bytes, | ||
} |
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.
@AntoineRR what method
does it give to the request object on Request:default()
?
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.
From actix_web:
impl Default for Method {
#[inline]
fn default() -> Method {
Method::GET
}
}
The default method is a GET then. It shouldn't matter for the const router, I just wanted a request to use the execute_http_function
method, but it shouldn't be used in the case of the const router
@@ -44,7 +42,7 @@ impl Router<String, Method> for ConstRouter { | |||
event_loop.context("Event loop must be provided to add a route to the const router")?; | |||
|
|||
pyo3_asyncio::tokio::run_until_complete(event_loop, async move { | |||
let output = execute_function(function, number_of_params, is_async) | |||
let output = execute_http_function(&Request::default(), function) |
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.
Good catch! Thanks!
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.
You're welcome ;)
I think it makes sense to only have one method to execute the function, as we will only have to change this one for an impact on HttpRouter
and ConstRouter
at the same time!
All looks good from the first glance. I have one last question - is I will just try a final run and test before approving 😄 Great work 👍 ✨ |
I'm glad you like it! |
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.
LGTM! 👍 🚀
Great work!
Description
This PR is a big refactor of Robyn's core. It aims at simplifying the code by factorizing it and introducing new useful structs. Here is a description of what I've done to achieve this:
Request
struct that wraps the parameters of a request (queries
,headers
,method
,params
, andbody
)Request
struct in request handlers and executors instead of using each parameters of a request separatelyFunctionInfo
struct to describe functions coming from Python. This struct is made available in the Python code too and wrapshandler
,is_async
andnumber_of_params
FunctionInfo
struct replacehandler
,is_async
andnumber_of_params
in every function callexecute_function
function that was used by the const router has been removed as it was very similar toexecute_http_function
. Const router now usesexecute_http_function
(not sure about this one, let me know if I should restoreexecute_function
which usedtokio::task::spawn_blocking
whileexecute_http_function
doesn't)This a big PR and it affects a lot of modules. It may need some time to be fully reviewed, do not hesitate to ask me questions about it and ask me to restore some parts if I made mistakes :)