Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
25 changes: 14 additions & 11 deletions crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ pub struct FnKindView {
/// See <https://willcrichton.net/notes/defeating-coherence-rust/> 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"),
Expand All @@ -437,23 +439,24 @@ 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,)>>
ExportFunctionForScheduledTable<'de, TableRow, FnKindReducer> for F
{
}

#[cfg(feature = "unstable")]
impl<
'de,
TableRow: SpacetimeType + Serialize + Deserialize<'de>,
Ret: SpacetimeType + Serialize + Deserialize<'de>,
F: Procedure<'de, (TableRow,), Ret>,
> ExportFunctionForScheduledTable<'de, TableRow, FnKindProcedure<Ret>> 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<Ret>> for F
// {
// }

// the macro generates <T as SpacetimeType>::make_type::<DummyTypespace>
pub struct DummyTypespace;
Expand Down
13 changes: 8 additions & 5 deletions crates/schema/src/def/validate/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ fn identifier(name: Box<str>) -> Result<Identifier> {
fn check_scheduled_functions_exist(
tables: &mut IdentifierMap<TableDef>,
reducers: &IndexMap<Identifier, ReducerDef>,
procedures: &IndexMap<Identifier, ProcedureDef>,
_procedures: &IndexMap<Identifier, ProcedureDef>,
) -> Result<()> {
let validate_params =
|params_from_function: &ProductType, table_row_type_ref: AlgebraicTypeRef, function_name: &str| {
Expand All @@ -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(),
Expand Down
Loading