diff --git a/crates/bindings/src/lib.rs b/crates/bindings/src/lib.rs index 6479bdba771..6c27ea0f7b7 100644 --- a/crates/bindings/src/lib.rs +++ b/crates/bindings/src/lib.rs @@ -728,16 +728,17 @@ pub use spacetimedb_bindings_macro::reducer; // TODO(procedure-http): add example with an HTTP request. // TODO(procedure-transaction): document obtaining and using a transaction within a procedure. /// -/// # Scheduled procedures +// TODO(scheduled-procedures): Uncomment below docs. +// /// # Scheduled procedures // TODO(docs): after moving scheduled reducer docs into table secion, link there. -/// -/// Like [reducer]s, procedures can be made **scheduled**. -/// This allows calling procedures at a particular time, or in a loop. -/// It also allows reducers to enqueue procedure runs. -/// -/// Scheduled procedures are called on a best-effort basis and may be slightly delayed in their execution -/// when a database is under heavy load. -/// +// /// +// /// Like [reducer]s, procedures can be made **scheduled**. +// /// This allows calling procedures at a particular time, or in a loop. +// /// It also allows reducers to enqueue procedure runs. +// /// +// /// Scheduled procedures are called on a best-effort basis and may be slightly delayed in their execution +// /// when a database is under heavy load. +// /// /// [clients]: https://spacetimedb.com/docs/#client // TODO(procedure-async): update docs and examples with `async`-ness. #[doc(inline)] diff --git a/crates/bindings/src/rt.rs b/crates/bindings/src/rt.rs index 08da263ea68..18bdb81a24c 100644 --- a/crates/bindings/src/rt.rs +++ b/crates/bindings/src/rt.rs @@ -424,7 +424,9 @@ pub struct FnKindView { /// See for details on this technique. #[cfg_attr( feature = "unstable", - doc = "It will be one of [`FnKindReducer`] or [`FnKindProcedure`] in modules that compile successfully." + // TODO(scheduled-procedures): uncomment this, delete other line + // doc = "It will be one of [`FnKindReducer`] or [`FnKindProcedure`] in modules that compile successfully." + doc = "It will be [`FnKindReducer`] in modules that compile successfully." )] #[cfg_attr( not(feature = "unstable"), @@ -437,7 +439,7 @@ pub struct FnKindView { note = "views cannot be scheduled", note = "the scheduled function must take `{TableRow}` as its sole argument", note = "e.g: `fn scheduled_reducer(ctx: &ReducerContext, arg: {TableRow})`", - note = "or `fn scheduled_procedure(ctx: &mut ProcedureContext, arg: {TableRow})`" + // note = "or `fn scheduled_procedure(ctx: &mut ProcedureContext, arg: {TableRow})`" )] pub trait ExportFunctionForScheduledTable<'de, TableRow, FnKind> {} impl<'de, TableRow: SpacetimeType + Serialize + Deserialize<'de>, F: Reducer<'de, (TableRow,)>> @@ -445,15 +447,16 @@ impl<'de, TableRow: SpacetimeType + Serialize + Deserialize<'de>, F: Reducer<'de { } -#[cfg(feature = "unstable")] -impl< - 'de, - TableRow: SpacetimeType + Serialize + Deserialize<'de>, - Ret: SpacetimeType + Serialize + Deserialize<'de>, - F: Procedure<'de, (TableRow,), Ret>, - > ExportFunctionForScheduledTable<'de, TableRow, FnKindProcedure> for F -{ -} +// TODO(scheduled-procedures): uncomment this to syntactically allow scheduled procedures. +// #[cfg(feature = "unstable")] +// impl< +// 'de, +// TableRow: SpacetimeType + Serialize + Deserialize<'de>, +// Ret: SpacetimeType + Serialize + Deserialize<'de>, +// F: Procedure<'de, (TableRow,), Ret>, +// > ExportFunctionForScheduledTable<'de, TableRow, FnKindProcedure> for F +// { +// } // the macro generates ::make_type:: pub struct DummyTypespace; diff --git a/crates/bindings/tests/ui/views.stderr b/crates/bindings/tests/ui/views.stderr index 9f46b8ff2e8..3796574ce28 100644 --- a/crates/bindings/tests/ui/views.stderr +++ b/crates/bindings/tests/ui/views.stderr @@ -408,3 +408,29 @@ error[E0277]: the trait bound `NotSpacetimeType: SpacetimeType` is not satisfied ColId and $N others = note: required for `Option` to implement `SpacetimeType` + +error[E0631]: type mismatch in function arguments + --> tests/ui/views.rs:142:56 + | +142 | #[spacetimedb::table(name = scheduled_table, scheduled(scheduled_table_view))] + | -------------------------------------------------------^^^^^^^^^^^^^^^^^^^^--- + | | | + | | expected due to this + | required by a bound introduced by this call +... +154 | fn scheduled_table_view(_: &ViewContext, _args: ScheduledTable) -> Vec { + | ------------------------------------------------------------------------------ found signature defined here + | + = note: expected function signature `for<'a> fn(&'a ReducerContext, ScheduledTable) -> _` + found function signature `fn(&ViewContext, ScheduledTable) -> _` + = note: required for `for<'a> fn(&'a ViewContext, ScheduledTable) -> Vec {scheduled_table_view}` to implement `Reducer<'_, (ScheduledTable,)>` + = note: required for `for<'a> fn(&'a ViewContext, ScheduledTable) -> Vec {scheduled_table_view}` to implement `ExportFunctionForScheduledTable<'_, ScheduledTable, {type error}>` +note: required by a bound in `scheduled_typecheck` + --> src/rt.rs + | + | pub const fn scheduled_typecheck<'de, Row, FnKind>(_x: impl ExportFunctionForScheduledTable<'de, Row, FnKind>) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `scheduled_typecheck` +help: consider wrapping the function in a closure + | +142 | #[spacetimedb::table(name = scheduled_table, scheduled(|arg0: &ReducerContext, arg1: ScheduledTable| scheduled_table_view(/* &ViewContext */, arg1)))] + | +++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++ diff --git a/crates/schema/src/def/validate/v9.rs b/crates/schema/src/def/validate/v9.rs index 43e31b3c1ae..f4a9505f4d8 100644 --- a/crates/schema/src/def/validate/v9.rs +++ b/crates/schema/src/def/validate/v9.rs @@ -1197,7 +1197,7 @@ fn identifier(name: Box) -> Result { fn check_scheduled_functions_exist( tables: &mut IdentifierMap, reducers: &IndexMap, - procedures: &IndexMap, + _procedures: &IndexMap, ) -> Result<()> { let validate_params = |params_from_function: &ProductType, table_row_type_ref: AlgebraicTypeRef, function_name: &str| { @@ -1222,10 +1222,13 @@ fn check_scheduled_functions_exist( if let Some(reducer) = reducers.get(&schedule.function_name) { schedule.function_kind = FunctionKind::Reducer; validate_params(&reducer.params, table.product_type_ref, &reducer.name).map_err(Into::into) - } else if let Some(procedure) = procedures.get(&schedule.function_name) { - schedule.function_kind = FunctionKind::Procedure; - validate_params(&procedure.params, table.product_type_ref, &procedure.name).map_err(Into::into) - } else { + } else + // TODO(scheduled-procedures): Uncomment this + // if let Some(procedure) = procedures.get(&schedule.function_name) { + // schedule.function_kind = FunctionKind::Procedure; + // validate_params(&procedure.params, table.product_type_ref, &procedure.name).map_err(Into::into) + // } else + { Err(ValidationError::MissingScheduledFunction { schedule: schedule.name.clone(), function: schedule.function_name.clone(),