-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(plugin): add TimeNow function to SchedulerService #4337
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
Conversation
Added new TimeNow RPC method to the SchedulerService host service that returns the current time in two formats: RFC3339Nano string and Unix milliseconds int64. This provides plugins with a standardized way to get current time information from the host system. The implementation includes: - TimeNowRequest/TimeNowResponse protobuf message definitions - Go host service implementation using time.Now() - Complete test coverage with format validation - Generated WASM interface code for plugin communication
Added LocalTimeZone field to TimeNowResponse message in the SchedulerService plugin host service. This field contains the server's local timezone name (e.g., 'America/New_York', 'UTC') providing plugins with timezone context alongside the existing RFC3339Nano and Unix milliseconds timestamps. The implementation includes: - New local_time_zone protobuf field definition - Go implementation using time.Now().Location().String() - Updated test coverage with timezone validation - Generated protobuf serialization/deserialization code
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.
Summary of Changes
Hello @deluan, 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 introduces a significant enhancement to the SchedulerService
plugin system by providing a new TimeNow
function. This function allows plugins to easily and reliably obtain the current time in various useful formats, including high-precision string, Unix timestamp, and local timezone information. This addition streamlines time-dependent operations within plugins, reducing complexity and ensuring consistency across the plugin ecosystem.
Highlights
- New
TimeNow
Function for Plugins: A newTimeNow
RPC method has been added to theSchedulerService
plugin API, allowing plugins to retrieve the current time directly from the host. - Multiple Time Formats: The
TimeNow
function returns the current time in three standardized formats: RFC3339Nano string, Unix milliseconds timestamp, and the local timezone name. - Enhanced Plugin Capabilities: This feature empowers plugins to perform time-based operations without needing to implement their own time-fetching mechanisms or rely on external services.
- Comprehensive Testing: New tests have been added to validate the accuracy and format of the returned time values, including parsing RFC3339Nano, checking Unix milliseconds, and verifying timezone information.
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.
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.
Pull Request Overview
Adds a new TimeNow
RPC to the SchedulerService plugin, returning the current time in RFC3339Nano format, Unix milliseconds, and the local timezone. Includes Go implementation, protocol buffer updates, WASM bindings, and end-to-end tests.
- Extended the SchedulerService API with a
TimeNow
method in.proto
and Go host/plugin layers - Implemented
schedulerService.timeNow
and exposed it through host and plugin WASM bindings - Added tests in
host_scheduler_test.go
to validate format, timestamp, and timezone correctness
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
plugins/host_scheduler.go | Added TimeNow host function and forwarded to schedulerService |
plugins/host_scheduler_test.go | Added tests for TimeNow response formats and timezone validation |
plugins/host/scheduler/scheduler.proto | Defined TimeNowRequest /TimeNowResponse and added TimeNow RPC |
plugins/host/scheduler/scheduler.pb.go | Generated Go types and interface update for TimeNow |
plugins/host/scheduler/scheduler_vtproto.pb.go | Added VTProto marshalling/unmarshalling for TimeNow messages |
plugins/host/scheduler/scheduler_plugin.pb.go | Added WASM plugin stub for _time_now and TimeNow wrapper |
plugins/host/scheduler/scheduler_host.pb.go | Registered time_now host function export in WASM environment |
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
This pull request introduces the TimeNow
function to the scheduler service for plugins. A potential issue was identified regarding the timezone name retrieval, which may not behave as expected on all systems. A suggestion was made to improve the test coverage for this specific behavior.
Updated the plugins README.md to document the new TimeNow function in the SchedulerService. The documentation includes detailed descriptions of the three return formats (RFC3339Nano, UnixMilli, LocalTimeZone), practical use cases, and a comprehensive Go code example showing how plugins can access current time information for logging, calculations, and timezone-aware operations.
Signed-off-by: Deluan <deluan@navidrome.org>
Added TimeNow method implementation to namedSchedulerService struct to satisfy the scheduler.SchedulerService interface contract. This method was recently added to the interface but the namedSchedulerService wrapper was not updated, causing compilation failures in plugin tests. The implementation is a simple pass-through to the underlying scheduler service since TimeNow doesn't require any special handling for named callbacks.
Description
This PR adds a new
TimeNow
function to the SchedulerService plugin system that returns the current time in multiple formats for plugin use. This enhancement allows plugins to access current time information in standardized formats without requiring additional host services.Related Issues
Type of Change
Checklist
Please review and check all that apply:
Changes Made
1. Enhanced SchedulerService Plugin API
TimeNow
RPC method to scheduler.protorfc3339_nano
: RFC3339 format with nanosecond precisionunix_milli
: Unix timestamp in millisecondslocal_time_zone
: Local timezone name (e.g., "UTC", "America/New_York")2. Implementation Details
TimeNowRequest
(empty) andTimeNowResponse
messagesTimeNow
method toSchedulerHostFunctions
interface andschedulerService
implementation3. Testing
host_scheduler_test.go
How to Test
make test PKG=./plugins/host/scheduler/...
make build
Technical Implementation
The implementation uses Go's
time.Now()
with:Format(time.RFC3339Nano)
for high-precision string representationUnixMilli()
for efficient numeric timestampLocation().String()
for timezone informationAdditional Notes
This enhancement maintains backward compatibility with existing scheduler functionality while adding new time access capabilities for plugins. The implementation follows existing patterns in the Navidrome plugin system and includes proper error handling and testing.