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

Allow *_config timeout to be specified as an env var/args. #26

Merged
merged 3 commits into from
Sep 7, 2023

Conversation

yjszk
Copy link
Contributor

@yjszk yjszk commented Jul 7, 2023

@aflanagan @shaneharter

If the number of monitors exceeds 150, the following error occurs in validate_config and apply_config.

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='cronitor.io', port=443): Max retries exceeded with url: /api/monitors.yaml (Caused by ReadTimeoutError("HTTPSConnectionPool(host='cronitor.io', port=443): Read timed out. (read timeout=10)"))

The timeout value is fixed to 10 seconds inside the library and we wanted to be able to set it with env var/args.

@yjszk yjszk changed the title Allow *_config timeout to be specified as an arg Allow *_config timeout to be specified as an argument Jul 7, 2023
@yjszk yjszk marked this pull request as draft July 10, 2023 14:38
@yjszk yjszk marked this pull request as ready for review July 10, 2023 14:39
@yjszk yjszk changed the title Allow *_config timeout to be specified as an argument Allow *_config timeout to be specified as an env var. Sep 1, 2023
@aflanagan
Copy link
Collaborator

Hi @yjszk thank you for the update! And apologies, I miscommunicated something in my last email. I was hoping that we could set it up to work from either an env var OR from the passed in argument as you had written it before. Some users like to configure everything from env vars, but many are just running the commands a couple of times locally and don't want the extra overhead. Possible to support both?

@yjszk yjszk changed the title Allow *_config timeout to be specified as an env var. Allow *_config timeout to be specified as an env var/args. Sep 1, 2023
@yjszk
Copy link
Contributor Author

yjszk commented Sep 2, 2023

Hi @yjszk thank you for the update! And apologies, I miscommunicated something in my last email. I was hoping that we could set it up to work from either an env var OR from the passed in argument as you had written it before. Some users like to configure everything from env vars, but many are just running the commands a couple of times locally and don't want the extra overhead. Possible to support both?

@aflanagan
I tried to support both. Environment variables are prioritised.
I had another problem while testing.I've created a separate pull request. Please use when it is good. thank you!
#29
#30

update readme on timeout issues

Use CRONITOR_TIMEOUT env var, not arg.

Support both args and env vars.

typo fix

env var is returned as stg type, it is int type.

Remove code duplication

revert CRONITOR_TIMEOUT logic

celerybeat_only var delete ,miss fix

add cronitor.timeout,test code fix
@@ -17,6 +17,13 @@
api_version = os.getenv('CRONITOR_API_VERSION', None)
environment = os.getenv('CRONITOR_ENVIRONMENT', None)
config = os.getenv('CRONITOR_CONFIG', None)
timeout = os.getenv('CRONITOR_TIMEOUT', None)
Copy link
Collaborator

@aflanagan aflanagan Sep 6, 2023

Choose a reason for hiding this comment

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

This is great!

One simplifying change I would like to consider (and am open to feedback on), is to simply set
timeout here, and then read that internally in the _put and as_yaml methods instead of passing timeout as an arg to the various *_config methods.

I know this isn't quite what I had suggest before, but it would simplify the code and the interface a little bit.

import cronitor
cronitor.timeout = 30
cronitor.apply_config()

internally the timeout attribute would just be set as, but could still be set directly on the module as done in the above example.

timeout = os.getenv('CRONITOR_TIMEOUT', 10)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! i have made the code shorter and easier to read.
And README has also been updated. Please check!

a452913

@aflanagan aflanagan merged commit 71cabc0 into cronitorio:master Sep 7, 2023
5 checks passed
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.

None yet

2 participants