Skip to content

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

Merged
merged 5 commits into from
Jul 13, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented Jul 13, 2025

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

  • New feature

Checklist

Please review and check all that apply:

  • My code follows the project's coding style
  • I have tested the changes locally
  • I have added or updated documentation as needed
  • I have added tests that prove my fix/feature works
  • All existing and new tests pass

Changes Made

1. Enhanced SchedulerService Plugin API

  • Added TimeNow RPC method to scheduler.proto
  • Returns current time in three formats:
    • rfc3339_nano: RFC3339 format with nanosecond precision
    • unix_milli: Unix timestamp in milliseconds
    • local_time_zone: Local timezone name (e.g., "UTC", "America/New_York")

2. Implementation Details

  • Protocol Buffer Definition: Added TimeNowRequest (empty) and TimeNowResponse messages
  • Go Implementation: Added TimeNow method to SchedulerHostFunctions interface and schedulerService implementation
  • Generated Code: Updated all protobuf bindings for Go and WebAssembly interfaces

3. Testing

  • Added comprehensive test coverage in host_scheduler_test.go
  • Tests validate RFC3339 format parsing, Unix milliseconds accuracy, and timezone matching
  • All existing tests continue to pass

How to Test

  1. Run the scheduler tests: make test PKG=./plugins/host/scheduler/...
  2. Build the project: make build
  3. All tests should pass and the new TimeNow functionality should be available to plugins

Technical Implementation

// Example usage from plugin perspective
timeResponse := scheduler.TimeNow()
// timeResponse.Rfc3339Nano = "2024-01-15T10:30:45.123456789Z"
// timeResponse.UnixMilli = 1705312245123
// timeResponse.LocalTimeZone = "UTC"

The implementation uses Go's time.Now() with:

  • Format(time.RFC3339Nano) for high-precision string representation
  • UnixMilli() for efficient numeric timestamp
  • Location().String() for timezone information

Additional 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.

deluan added 2 commits July 13, 2025 13:47
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
@Copilot Copilot AI review requested due to automatic review settings July 13, 2025 17:58
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 new TimeNow RPC method has been added to the SchedulerService 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

  1. 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.

Copy link
Contributor

@Copilot Copilot AI left a 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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

deluan added 3 commits July 13, 2025 14:04
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.
@deluan deluan changed the title Add TimeNow function with timezone support to SchedulerService plugin feat(plugin): add TimeNow function to SchedulerService Jul 13, 2025
@deluan deluan merged commit 5b73a4d into master Jul 13, 2025
20 checks passed
@deluan deluan deleted the feat/plugins-time branch July 13, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant