-
Couldn't load subscription status.
- Fork 1
Fix Linear Webhooks and other examples #6
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
base: develop
Are you sure you want to change the base?
Conversation
| print(f"Error: Missing required environment variables: {', '.join(missing_vars)}") | ||
| print("Please create a .env file with the following variables:") | ||
| print("\n".join([f"{var}=\"your_{var.lower()}\"" for var in required_vars])) | ||
| exit(1) |
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.
Using print statements for error handling and exit(1) to terminate the application is not recommended for production environments. It's better to use a logging framework for error messages, which offers more flexibility and control over how messages are recorded and viewed. Additionally, consider handling missing environment variables more gracefully by using exceptions or a dedicated error handling mechanism.
Recommended Change:
Replace print statements with logging and consider using exceptions for error handling:
import logging
logging.error(f"Missing required environment variables: {', '.join(missing_vars)}")
raise EnvironmentError("Required environment variables are missing")| print("Listening for Linear events at: http://0.0.0.0:8000/linear/events") | ||
| print("Use a tool like ngrok to expose this endpoint to the internet.") | ||
| print("Then configure your Linear webhook to point to: https://your-ngrok-url/linear/events") | ||
| uvicorn.run(fastapi_app, host="0.0.0.0", port=8000) No newline at end of file |
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.
Listening on all network interfaces (0.0.0.0) can expose the application to unnecessary security risks if not properly secured. It's recommended to bind the server to 127.0.0.1 if it's only meant to be accessed locally or ensure proper security measures are in place (like a firewall) when exposing it to the internet.
Recommended Change:
Change the host to 127.0.0.1 if local access is sufficient:
uvicorn.run(fastapi_app, host="127.0.0.1", port=8000)| from codegen.extensions.events.codegen_app import CodegenApp | ||
| import modal | ||
|
|
||
| image = modal.Image.debian_slim(python_version="3.13").apt_install("git").pip_install("fastapi[standard]", "codegen>=v0.22.2") |
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.
The chaining of apt_install and pip_install methods in the Docker image setup could lead to inefficient caching and larger image sizes. Consider splitting these into separate layers or optimizing the Dockerfile to leverage build caching effectively. This can be achieved by grouping package installations or using multi-stage builds to minimize the final image size.
|
|
||
| image = modal.Image.debian_slim(python_version="3.13").apt_install("git").pip_install("fastapi[standard]", "codegen>=v0.22.2") | ||
| app = CodegenApp(name="test-linear", modal_api_key="", image=image) | ||
| app = CodegenApp(name="test-linear") |
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.
The application name "test-linear" is hardcoded in the instantiation of CodegenApp. To enhance flexibility and maintainability, consider externalizing this configuration to an environment variable or a configuration file. This approach allows for easier adjustments in different deployment environments without modifying the codebase.
| import logging | ||
| from logging import getLogger |
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.
Redundant Imports
The import statements for logging and from logging import getLogger are redundant. You can remove the specific import of getLogger and use logging.getLogger() instead, which will make the import section cleaner and avoid redundancy.
Recommended Change:
import logging
# from logging import getLogger # This line can be removed|
|
||
| @app.github.event("pull_request:labeled") |
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.
Missing Error Handling in Event Registration
The event handler for pull_request:labeled does not include any error handling. This could lead to unhandled exceptions if the event data is not as expected or if there are issues during the handling process. It's recommended to add error handling to ensure the application behaves gracefully under error conditions.
Suggested Improvement:
@app.github.event("pull_request:labeled")
def handle_labeled(event: PullRequestLabeledEvent):
try:
# existing code
except Exception as e:
logger.error(f"Error handling labeled event: {e}")| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| image = modal.Image.debian_slim(python_version="3.13").apt_install("git").pip_install("fastapi[standard]", "codegen==v0.26.3") |
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.
The specified Python version '3.13' in the modal.Image.debian_slim configuration may be incorrect or a typo, as Python 3.13 is not a released version. This could lead to issues when building the image or at runtime.
Recommendation: Verify the intended Python version and update it to a valid version, such as '3.9' or '3.10', to ensure compatibility and avoid deployment failures.
| app = CodegenApp("linear-bot") | ||
|
|
||
|
|
||
| @app.cls(secrets=[modal.Secret.from_dotenv()], keep_warm=1) |
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.
The keep_warm=1 setting in the @app.cls decorator is used to keep the serverless function warm, potentially improving response times. However, this setting might incur additional costs or have other implications depending on the platform's billing and performance characteristics.
Recommendation: Review the necessity and impact of the keep_warm setting in this context. If it's essential for performance, consider documenting its benefits and potential costs. If not, you might want to adjust or remove this setting to optimize resource usage and cost.
Changes
This PR fixes issues with the Linear webhooks and other examples:
Fixed import errors:
from codegen.extensions.events.app import CodegenApptofrom codegen.extensions.events.codegen_app import CodegenAppFixed initialization errors:
modal_api_keyandimage) from the CodegenApp initializationAdded a standalone version for the Linear webhooks example:
standalone.pythat can be run without ModalUpdated .env.template with the Zeeeepa team ID
These changes make it easier to get started with the examples, especially for users who want to run them locally without Modal.
Affected files