Add MAX_EXECUTIONS environment variable limit#5272
Conversation
- Fixed the `TypeError: info() takes 1 positional argument but 2 were given` exception when max_executions limit is reached. - Ensured environment re-evaluation in the `test_max_executions` unit test. - Mocked `update_task_enabled` correctly during tests.
- Handles ValueError if MAX_EXECUTIONS cannot be parsed as an integer. - Removes the invalid value from the environment to prevent repeated errors. - Adds test coverage for the invalid input case.
- Removed extra indentation by utilizing Python's short-circuit evaluation inside a single try-except block.
- Fail fast with log_fatal_and_exit on invalid env values - Move max_task_executions retrieval outside the task loop - Use correct log format args for metrics.logs.info - Clean up test mock assignments and assert SystemExit
ViniciustCosta
left a comment
There was a problem hiding this comment.
Seems good! Could you just add an evidence of it not blocking execution in dev environment?
Will do! |
|
/gcbrun |
+1 |
|
Changes are now present in |
These changes have now been present in |
letitz
left a comment
There was a problem hiding this comment.
Two nits below. LGTM % updating the PR description to match the variable rename.
| if not val: | ||
| return None | ||
| try: | ||
| return int(val) |
There was a problem hiding this comment.
[Optional] I think you could just remove the try/catch and let ValueError be raised instead.
| logs.info(f'Reached MAX_EXECUTIONS limit ({max_executions}). Exiting.') | ||
| if max_task_executions and execution_count >= max_task_executions: | ||
| logs.info( | ||
| 'Reached MAX_TASK_EXECUTIONS limit. Exiting.', |
There was a problem hiding this comment.
Consider inlining the limit value in the log message body instead of as metadata. It's small anyway.
This PR introduces a
MAX_EXECUTIONSenvironment variable that limits the number of tasks the bot will execute before exiting cleanly. It will facilitate testing locally moving forward.This is particularly useful when running a local bot with a
COMMAND_OVERRIDE, allowing developers to restrict the bot to a specific number of iterations rather than looping infinitely.Changes:
execution_counttracker to the maintask_loopinrun_bot.py.MAX_EXECUTIONSis set and reached.run_bot_test.py.