-
Notifications
You must be signed in to change notification settings - Fork 1
Add gocron scheduler for devbuild polling #257
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: main
Are you sure you want to change the base?
Conversation
- Integrated gocron scheduler to handle periodic polling of devbuild status. - Updated `NewRootForMessage` to accept and initialize the scheduler. - Modified `runCommandDevbuildTrigger` to schedule polling tasks. - Refactored devbuild polling logic into separate functions.
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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.
Hello @wuhuizuo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request introduces a gocron scheduler to periodically poll the status of devbuilds. It modifies the NewRootForMessage function to accept and initialize the scheduler, and updates runCommandDevbuildTrigger to schedule polling tasks. The devbuild polling logic has also been refactored into separate functions for better organization and reusability.
Highlights
- Scheduler Integration: Integrates
gocronto schedule periodic polling of devbuild status, improving automation. - Code Refactoring: Refactors devbuild polling logic into separate functions (
loopPollDevbuildStatusandpollDevbuildStatus) for better modularity and readability. - Context Updates: Updates
NewRootForMessageto accept and initialize thegocronscheduler, making it available throughout the application.
Changelog
Click here to see the changelog
- chatops-lark/cmd/server/main.go
- Imported the
gocronpackage. - Initialized the
gocronscheduler. - Passed the scheduler instance to
NewRootForMessage. - Started the scheduler and ensured it stops if the WebSocket client fails to start.
- Imported the
- chatops-lark/go.mod
- Added
github.com/jasonlvhit/gocron v0.0.1as a dependency.
- Added
- chatops-lark/go.sum
- Added checksums for
gocronand its dependencies.
- Added checksums for
- chatops-lark/pkg/events/handler/devbuild.go
- Added constants for context keys related to the devbuild polling scheduler and task.
- chatops-lark/pkg/events/handler/devbuild_poll.go
- Added
slicesandtimeimports. - Introduced
loopPollIntervalconstant for the polling interval. - Refactored
runCommandDevbuildPollto usepollDevbuildStatusandrenderDevbuildStatusForLark. - Created
loopPollDevbuildStatusto poll until a final status is reached. - Created
pollDevbuildStatusto handle the actual API call.
- Added
- chatops-lark/pkg/events/handler/devbuild_trigger.go
- Imported the
gocronpackage. - Scheduled a polling task using the
gocronscheduler inrunCommandDevbuildTrigger.
- Imported the
- chatops-lark/pkg/events/handler/root.go
- Imported the
gocronpackage. - Modified the
rootHandlerstruct to include acronSchedulerfield. - Modified
NewRootForMessageto accept acronSchedulerparameter and initialize thecronSchedulerfield inrootHandler. - Added
AsyncNotifyHandlertoCommandConfigstruct.
- Imported the
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A scheduler's gentle hand,
Tasks it starts across the land,
Polling 'til it's done,
Status found and won,
Devbuild's fate, we understand.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request introduces a gocron scheduler to handle periodic polling of devbuild status, updates NewRootForMessage to accept and initialize the scheduler, modifies runCommandDevbuildTrigger to schedule polling tasks, and refactors devbuild polling logic into separate functions. Overall, the changes seem well-structured and address the intended functionality. However, there are a few areas that could be improved for clarity, error handling, and resource management.
Summary of Findings
- Context Value Usage: In
runCommandDevbuildTrigger, the context values are retrieved using empty strings as keys, which is incorrect and will lead to unexpected behavior. The correct context keys (ctxKeyDevbuildPollSchedulerandctxKeyDevbuildPollTask) should be used to retrieve the scheduler and polling function. - Scheduler Start/Stop: The scheduler's
Startmethod returns a channel to stop the scheduler, which is used when the WebSocket client fails to start. However, there's no mechanism to stop the scheduler if the application exits normally. This could lead to resource leaks. - Error Handling in Main: The error handling in
main.gocould be improved by ensuring that the cron scheduler is stopped before exiting the application, even if the WebSocket client starts successfully.
Merge Readiness
The pull request requires changes before merging. The context value usage in runCommandDevbuildTrigger must be corrected to ensure the scheduler and polling function are properly retrieved. Additionally, the scheduler's lifecycle should be managed more carefully to prevent resource leaks. I am unable to approve this pull request, and recommend that it not be merged until these issues are addressed, and that others review and approve this code before merging.
| pollScheduler := ctx.Value("").(*gocron.Scheduler) | ||
| pollFunc := ctx.Value("").(func(string)) |
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 context values are being retrieved using empty strings as keys, which is incorrect. Use the constants defined in devbuild.go (ctxKeyDevbuildPollScheduler and ctxKeyDevbuildPollTask) to retrieve the scheduler and polling function. This is a critical error as it will cause the application to not work as expected.
| pollScheduler := ctx.Value("").(*gocron.Scheduler) | |
| pollFunc := ctx.Value("").(func(string)) | |
| pollScheduler := ctx.Value(ctxKeyDevbuildPollScheduler).(*gocron.Scheduler) | |
| pollFunc := ctx.Value(ctxKeyDevbuildPollTask).(func(string)) |
| if err := consumerCli.Start(context.Background()); err != nil { | ||
| csStop <- true | ||
| log.Fatal().Err(err).Msg("run failed for Lark WebSocket client") | ||
| } |
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.
Consider adding a defer statement to ensure the scheduler is stopped when the main function exits, even if the WebSocket client starts successfully. This will prevent potential resource leaks if the application exits normally.
| if err := consumerCli.Start(context.Background()); err != nil { | |
| csStop <- true | |
| log.Fatal().Err(err).Msg("run failed for Lark WebSocket client") | |
| } | |
| if err := consumerCli.Start(context.Background()); err != nil { | |
| csStop <- true | |
| log.Fatal().Err(err).Msg("run failed for Lark WebSocket client") | |
| } else { | |
| defer func() { | |
| csStop <- true // Ensure scheduler is stopped on normal exit | |
| }() | |
| } |
|
@gemini-code-assist[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
NewRootForMessageto accept and initialize the scheduler.runCommandDevbuildTriggerto schedule polling tasks.