[WIP] Cluster mode example: factor out the database#182
[WIP] Cluster mode example: factor out the database#182gaborfeher wants to merge 2 commits intoa2aproject:mainfrom
Conversation
specific logic from taskstore.go into db_taskstore.go
Summary of ChangesHello @gaborfeher, 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! This pull request refactors the database interaction logic within the cluster mode example. The primary goal is to separate the database-specific implementation from the generic task storage mechanism. This is achieved by introducing a Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the database-specific logic out of taskstore.go by introducing a Database interface and a MySQLDBAdapter implementation. This is a great improvement for modularity and prepares the ground for supporting other database backends. The code is well-structured and the abstraction is clean. I have a few suggestions to remove an unused parameter from the Update method signature across the new interface and implementation, which will make the code even clearer.
| } | ||
|
|
||
| // Update persists an updated task and event. | ||
| func (a *MySQLDBAdapter) Update(ctx context.Context, task *a2a.Task, event a2a.Event, newVersion int64, prevVersion int64, protocolVersion a2a.ProtocolVersion) (bool, error) { |
There was a problem hiding this comment.
The protocolVersion parameter is not used within this function. To align with the interface change and improve clarity, it should be removed from the function signature.
| func (a *MySQLDBAdapter) Update(ctx context.Context, task *a2a.Task, event a2a.Event, newVersion int64, prevVersion int64, protocolVersion a2a.ProtocolVersion) (bool, error) { | |
| func (a *MySQLDBAdapter) Update(ctx context.Context, task *a2a.Task, event a2a.Event, newVersion int64, prevVersion int64) (bool, error) { |
| Create(ctx context.Context, task *a2a.Task, event a2a.Event, newVersion int64, protocolVersion a2a.ProtocolVersion) error | ||
| // Update persists an updated task and event. | ||
| // It returns true if the operation was successful (or false if optimistic locking failed). | ||
| Update(ctx context.Context, task *a2a.Task, event a2a.Event, newVersion int64, prevVersion int64, protocolVersion a2a.ProtocolVersion) (bool, error) |
There was a problem hiding this comment.
The protocolVersion parameter is unused in implementations of this Update method (e.g., MySQLDBAdapter). Since the protocol version of a task is not expected to change after creation, this parameter should be removed from the Update method signature to improve code clarity. This will require updating the method signature here, in the MySQLDBAdapter.Update implementation, and the call to s.db.Update in DBTaskStore.Save.
| Update(ctx context.Context, task *a2a.Task, event a2a.Event, newVersion int64, prevVersion int64, protocolVersion a2a.ProtocolVersion) (bool, error) | |
| Update(ctx context.Context, task *a2a.Task, event a2a.Event, newVersion int64, prevVersion int64) (bool, error) |
| return a2a.TaskVersionMissing, err | ||
| } | ||
| } else { | ||
| success, err := s.db.Update(ctx, task, event, newVersion, int64(prevVersion), s.version) |
There was a problem hiding this comment.
To align with the suggested change of removing the unused protocolVersion parameter from the db.Update method, this call should be updated accordingly.
| success, err := s.db.Update(ctx, task, event, newVersion, int64(prevVersion), s.version) | |
| success, err := s.db.Update(ctx, task, event, newVersion, int64(prevVersion)) |
specific logic from taskstore.go into db_taskstore.go