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

feat: control dev mode with env var #877

Merged
merged 15 commits into from
Jul 19, 2024

Conversation

VishnuSanal
Copy link
Contributor

Description

This PR fixes #62

Copy link

vercel bot commented Jul 1, 2024

@VishnuSanal is attempting to deploy a commit to the sparckles Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codspeed-hq bot commented Jul 1, 2024

CodSpeed Performance Report

Merging #877 will not alter performance

Comparing VishnuSanal:hot-reload-env-var (8f3c442) with main (7b025a3)

Summary

✅ 110 untouched benchmarks

robyn/cli.py Outdated Show resolved Hide resolved
@@ -23,7 +23,7 @@ def __init__(self) -> None:
"--dev",
dest="dev",
action="store_true",
default=False,
default=None,
Copy link
Member

Choose a reason for hiding this comment

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

Let's document this decision?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sansyrox It will be defaulted to false if an environment variable is not found. (since the fallback value to os.getenv on cli#run is false) Should we still document it?

Copy link
Member

Choose a reason for hiding this comment

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

@VishnuSanal , I want you to document the decision that the env variable will have a priority over the cli flag.

I believe we should prioritise cli flag over the env variable.

@sansyrox
Copy link
Member

sansyrox commented Jul 5, 2024

Also, could you add a way to control the dev mode in app.start(debug=True)

@VishnuSanal
Copy link
Contributor Author

Also, could you add a way to control the dev mode in app.start(debug=True)

the decision to turn on/off the dev mode would have been made before we reach robyn#start. adding the debug param would be redundant as of now. or, to implement this then would require the restarting of server as mentioned here. can we move this to be a new issue?

@sansyrox
Copy link
Member

sansyrox commented Jul 5, 2024

the decision to turn on/off the dev mode would have been made before we reach robyn#start

And why is that? I thought you were implementing python app.py --dev And even if it is robyn app.py Why is it being invoked before start?

@VishnuSanal
Copy link
Contributor Author

the decision to turn on/off the dev mode would have been made before we reach robyn#start

And why is that?

what I meant with "the decision to turn on/off the dev mode would have been made before we reach robyn#start" is that that the control flow reaches robyn#start from cli#run => cli#start_dev_server or cli#run => cli#start_app_normally.

I thought you were implementing python app.py --dev And even if it is robyn app.py Why is it being invoked before start?

I didn't get you? yeah, I am implementing the toggle for dev mode from env vars; but, in both cases, wouldn't the decision to switch to whether to start app normally or to start the dev server would have been made before the init?

@VishnuSanal VishnuSanal requested a review from sansyrox July 6, 2024 16:02
robyn/__init__.py Outdated Show resolved Hide resolved
robyn/cli.py Show resolved Hide resolved
robyn/__init__.py Outdated Show resolved Hide resolved
@sansyrox
Copy link
Member

sansyrox commented Jul 9, 2024

@VishnuSanal , updated the PR. Do have a look.

@sansyrox
Copy link
Member

sansyrox commented Jul 9, 2024

@VishnuSanal , could you do a self review/review on my changes? And then I can do a final review 😄

Copy link
Contributor Author

@VishnuSanal VishnuSanal left a comment

Choose a reason for hiding this comment

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

it doesn't work as expected in my testing.

(.venv) RobynApp $ python3 app.py
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /
INFO:robyn.logger:Robyn version: 0.56.1
INFO:robyn.logger:Starting server at http://0.0.0.0:8080
INFO:actix_server.builder:starting 1 workers
INFO:actix_server.server:Actix runtime found; starting in Actix runtime
^CINFO:actix_server.server:SIGINT received; starting forced shutdown
INFO:actix_server.worker:shutting down idle worker
INFO:actix_server.accept:accept thread stopped
Aborted (core dumped)

(.venv) RobynApp $ robyn app.py
Starting dev server...
Reloading /home/vishnu/Robyn/RobynApp/app.py...
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /
INFO:robyn.logger:Robyn version: 0.56.1
INFO:robyn.logger:Starting server at http://0.0.0.0:8080
INFO:actix_server.builder:starting 1 workers
INFO:actix_server.server:Actix runtime found; starting in Actix runtime
^CINFO:actix_server.server:SIGINT received; starting forced shutdown
INFO:actix_server.accept:accept thread stopped
INFO:actix_server.worker:shutting down idle worker

(.venv) RobynApp $ cat robyn.env
ROBYN_DEV_MODE=True

@sansyrox
Copy link
Member

What is unexpected here @VishnuSanal ?

@VishnuSanal
Copy link
Contributor Author

What is unexpected here @VishnuSanal ?

I have the environemnt variable set to true, but no warning is shown when running python3 app.py (CMIIW).

@sansyrox
Copy link
Member

@VishnuSanal , is it actually running in dev mode?

@VishnuSanal
Copy link
Contributor Author

@VishnuSanal , is it actually running in dev mode?

it wasn't actually running in dev mode + the warning wasn't being shown, even after setting the env var. Please refer to the logs attached.

(.venv) RobynApp $ python3 app.py
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /
INFO:robyn.logger:Robyn version: 0.56.1
INFO:robyn.logger:Starting server at http://0.0.0.0:8080
INFO:actix_server.builder:starting 1 workers
INFO:actix_server.server:Actix runtime found; starting in Actix runtime
^CINFO:actix_server.server:SIGINT received; starting forced shutdown
INFO:actix_server.worker:shutting down idle worker
INFO:actix_server.accept:accept thread stopped
Aborted (core dumped)

(.venv) RobynApp $ robyn app.py
Starting dev server...
Reloading /home/vishnu/Robyn/RobynApp/app.py...
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /
INFO:robyn.logger:Robyn version: 0.56.1
INFO:robyn.logger:Starting server at http://0.0.0.0:8080
INFO:actix_server.builder:starting 1 workers
INFO:actix_server.server:Actix runtime found; starting in Actix runtime
^CINFO:actix_server.server:SIGINT received; starting forced shutdown
INFO:actix_server.accept:accept thread stopped
INFO:actix_server.worker:shutting down idle worker

(.venv) RobynApp $ cat robyn.env
ROBYN_DEV_MODE=True

@sansyrox sansyrox force-pushed the hot-reload-env-var branch from f6b088c to 606588a Compare July 15, 2024 14:39
@sansyrox
Copy link
Member

@VishnuSanal , have a look once.

@sansyrox sansyrox force-pushed the hot-reload-env-var branch from 16faef2 to 47da13f Compare July 15, 2024 15:02
@VishnuSanal
Copy link
Contributor Author

yeps, works as expected! attaching the logs for reference.

(.venv) testing_application $ cat robyn.env
ROBYN_DEV_MODE=True

(.venv) testing_application $ python3 app.py
Ignoring ROBYN_DEV_MODE environment variable. Dev mode is not supported in the python wrapper.
Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py

(.venv) testing_application $ robyn app.py
Starting dev server...
Reloading the server
argumens
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /
INFO:robyn.logger:Robyn version: 0.56.1
INFO:robyn.logger:Starting server at http://0.0.0.0:8080
INFO:actix_server.builder:starting 1 workers
INFO:actix_server.server:Actix runtime found; starting in Actix runtime
^CINFO:actix_server.server:SIGINT received; starting forced shutdown
INFO:actix_server.worker:shutting down idle worker
INFO:actix_server.accept:accept thread stopped
(.venv) testing_application $ cat robyn.env
ROBYN_DEV_MODE=False

(.venv) testing_application $ python3 app.py
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /
INFO:robyn.logger:Robyn version: 0.56.1
INFO:robyn.logger:Starting server at http://0.0.0.0:8080
INFO:actix_server.builder:starting 1 workers
INFO:actix_server.server:Actix runtime found; starting in Actix runtime
^CINFO:actix_server.server:SIGINT received; starting forced shutdown
INFO:actix_server.worker:shutting down idle worker
INFO:actix_server.accept:accept thread stopped
Aborted (core dumped)

(.venv) testing_application $ robyn app.py
INFO:robyn.logger:SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.
INFO:robyn.logger:Added route HttpMethod.GET /
INFO:robyn.logger:Robyn version: 0.56.1
INFO:robyn.logger:Starting server at http://0.0.0.0:8080
INFO:actix_server.builder:starting 1 workers
INFO:actix_server.server:Actix runtime found; starting in Actix runtime
^CINFO:actix_server.server:SIGINT received; starting forced shutdown
INFO:actix_server.worker:shutting down idle worker
INFO:actix_server.accept:accept thread stopped

Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

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

LGTM 😄

@sansyrox sansyrox merged commit aac58bb into sparckles:main Jul 19, 2024
58 of 59 checks passed
@VishnuSanal VishnuSanal deleted the hot-reload-env-var branch August 22, 2024 06:04
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.

Enable hot reloading by default
2 participants