Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ scope the host bound it to, documents for its `teq.*` state and the queue port
for the queues `queues.json` declares. `tinyeventqueues-bus` (feature
`storage`) publishes `collection_specs()` for the module's document state and
the shipped `queues.json`. The private module configuration must include the
host-provided `storage_callback` destination; setup fails closed if it is
missing or unavailable.
host-provided `storage_callback` destination: the unique name of the callback
binding admitted for this instance, or `ai.tinyhumans.tinystorage.Storage` for
a host that serves one storage service for every module. Setup fails closed if
it is missing or unavailable.

The module takes a private configuration blob:
`{"storage_callback": ":1.42", "queues": <queues.json>, "pipeline": <pipeline.json>, "timer":
Expand Down
17 changes: 16 additions & 1 deletion crates/tinyeventqueues/examples/verify_github_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,41 @@
//! ```

use std::io;
use std::sync::Arc;
use std::time::Duration;

use tinybus::Connection;
use tinybus::broker::Broker;
use tinybus::module::ModuleHost;
use tinybus::transport::memory::MemoryBus;
use tinyeventqueues::{StatsRequest, StatsResponse, names};
use tinystoragedrivers_api::StorageBackend;
use tinystoragedrivers_busproxy::{HOST_NAME, PerCallerEndpoint, StorageServer, serve};
use tinystoragedrivers_testkit::MemoryBackend;
use tinystoragedrivers_types::Scope;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (release_url, archive, sha256) = arguments()?;
let bus = MemoryBus::new();
let broker = Broker::new();
let broker_task = broker.spawn(bus.clone());
// The module refuses to start without host storage. Serve memory storage
// under the shared storage service name, as a host that serves one storage
// service for every module does.
let host = Connection::connect(bus.connect().await?).await?;
let backend = Arc::new(MemoryBackend::new());
let endpoint = PerCallerEndpoint::new(move |_sender| {
let storage = backend.for_scope(&Scope::new("local").ok()?).ok()?;
Some(StorageServer::new(storage))
});
let _served = serve(&host, Arc::new(endpoint)).await?;
let module_host = ModuleHost::new(broker);
let info = module_host.load_github_release(
&release_url,
&archive,
Some(&sha256),
serde_json::Value::default(),
serde_json::json!({ "storage_callback": HOST_NAME }),
)?;

if info.name != env!("CARGO_PKG_NAME") {
Expand Down
3 changes: 2 additions & 1 deletion crates/tinyeventqueues/src/tinybus_module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ both.
the one scope the host bound the module to: documents for the `teq.*` state
(declared by `tinyeventqueues_bus::storage::collection_specs()`) and the
queue port for the manifest's queues. The host-provided `storage_callback`
setting names the unique callback binding admitted for this module instance;
setting names the unique callback binding admitted for this module instance,
or the shared storage service of a host that serves one for every module;
missing or unusable host storage fails setup rather than starting with an
ephemeral engine.
- `host.rs`: `BusHost`, the pipeline's `Host`, calling the host's optional
Expand Down
4 changes: 3 additions & 1 deletion crates/tinyeventqueues/src/tinybus_module/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
//! ```
//!
//! `storage_callback` is the unique destination of the storage callback
//! admitted by the host for this module instance. `queues` is a `queues.json`
//! admitted by the host for this module instance, or the shared storage
//! service name (`ai.tinyhumans.tinystorage.Storage`) of a host that serves one
//! storage service for every module. `queues` is a `queues.json`
//! document and `pipeline` a `pipeline.json` document, both parsed as strictly
//! as the files are. A host that serves the module's queues should declare the
//! same manifest it passes here: its queue port admits an `EnsureQueue` only
Expand Down
33 changes: 20 additions & 13 deletions crates/tinyeventqueues/src/tinybus_module/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,27 @@ pub(crate) async fn open(connection: Connection, callback: Option<&str>) -> Resu
))
})?;
let destination_display = destination.to_string();
tinystoragedrivers_busproxy::connect_storage_at(connection, destination)
.await
.map_err(|error| {
Error::from(
StorageError::new(
error.kind(),
format!(
"storage_callback {destination_display} is unavailable: {}",
error.message()
),
)
.with_source(error),
// A host that serves one storage service for every module names
// that service instead of a per-instance callback binding. The
// name is exact: any other name is used as-is, an absent one still
// fails, and so does a service nobody owns.
let connected = if destination.as_str() == tinystoragedrivers_busproxy::HOST_NAME {
tinystoragedrivers_busproxy::connect_storage(connection).await
} else {
tinystoragedrivers_busproxy::connect_storage_at(connection, destination).await
};
connected.map_err(|error| {
Error::from(
StorageError::new(
error.kind(),
format!(
"storage_callback {destination_display} is unavailable: {}",
error.message()
),
)
})?
.with_source(error),
)
})?
}
None => {
return Err(Error::from(
Expand Down
3 changes: 2 additions & 1 deletion docs/specs/event-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ are in `tinyeventqueues-bus`.
Without the callback destination, setup fails; there is no in-memory
fallback.
- Configuration: the host-provided private blob carries `storage_callback`
(the unique name for the admitted storage callback), plus `queues` (a `queues.json`
(the unique name for the admitted storage callback, or the shared storage
service name `ai.tinyhumans.tinystorage.Storage`), plus `queues` (a `queues.json`
document), `pipeline` (a `pipeline.json` document) and `timer` bounds;
absent fields run the shipped files. The manifest is applied through the
queue port at setup.
Expand Down
Loading