Files
navidrome/plugins/pdk/rust/nd-pdk-capabilities/src/scheduler.rs
T
Deluan Quintão fda35dd8ce feat(plugins): add similar songs retrieval functions and improve duration consistency (#4933)
* feat: add duration filtering for similar songs matching

Signed-off-by: Deluan <deluan@navidrome.org>

* test: refactor expectations for similar songs in provider matching tests

Signed-off-by: Deluan <deluan@navidrome.org>

* feat(plugins): add functions to retrieve similar songs by track, album, and artist

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(plugins): support uint32 in ndpgen

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(plugins): update duration field to use seconds as float instead of milliseconds as uint32

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: add helper functions for Rust's skip_serializing_if with numeric types

Signed-off-by: Deluan <deluan@navidrome.org>

* feat(provider): enhance track matching logic to fallback to title match when duration-filtered tracks fail

---------

Signed-off-by: Deluan <deluan@navidrome.org>
2026-01-26 18:28:41 -05:00

79 lines
2.7 KiB
Rust

// Code generated by ndpgen. DO NOT EDIT.
//
// This file contains export wrappers for the SchedulerCallback capability.
// It is intended for use in Navidrome plugins built with extism-pdk.
use serde::{Deserialize, Serialize};
// Helper functions for skip_serializing_if with numeric types
#[allow(dead_code)]
fn is_zero_i32(value: &i32) -> bool { *value == 0 }
#[allow(dead_code)]
fn is_zero_u32(value: &u32) -> bool { *value == 0 }
#[allow(dead_code)]
fn is_zero_i64(value: &i64) -> bool { *value == 0 }
#[allow(dead_code)]
fn is_zero_u64(value: &u64) -> bool { *value == 0 }
#[allow(dead_code)]
fn is_zero_f32(value: &f32) -> bool { *value == 0.0 }
#[allow(dead_code)]
fn is_zero_f64(value: &f64) -> bool { *value == 0.0 }
/// SchedulerCallbackRequest is the request provided when a scheduled task fires.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchedulerCallbackRequest {
/// ScheduleID is the unique identifier for this scheduled task.
/// This is either the ID provided when scheduling, or an auto-generated UUID if none was specified.
#[serde(default)]
pub schedule_id: String,
/// Payload is the payload data that was provided when the task was scheduled.
/// Can be used to pass context or parameters to the callback handler.
#[serde(default)]
pub payload: String,
/// IsRecurring is true if this is a recurring schedule (created via ScheduleRecurring),
/// false if it's a one-time schedule (created via ScheduleOneTime).
#[serde(default)]
pub is_recurring: bool,
}
/// Error represents an error from a capability method.
#[derive(Debug)]
pub struct Error {
pub message: String,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for Error {}
impl Error {
pub fn new(message: impl Into<String>) -> Self {
Self { message: message.into() }
}
}
/// CallbackProvider provides the OnCallback function.
pub trait CallbackProvider {
fn on_callback(&self, req: SchedulerCallbackRequest) -> Result<(), Error>;
}
/// Register the on_callback export.
/// This macro generates the WASM export function for this method.
#[macro_export]
macro_rules! register_scheduler_callback {
($plugin_type:ty) => {
#[extism_pdk::plugin_fn]
pub fn nd_scheduler_callback(
req: extism_pdk::Json<$crate::scheduler::SchedulerCallbackRequest>
) -> extism_pdk::FnResult<()> {
let plugin = <$plugin_type>::default();
$crate::scheduler::CallbackProvider::on_callback(&plugin, req.into_inner())?;
Ok(())
}
};
}