Skip to main content

datapress_datafusion/
lib.rs

1//! `datapress-datafusion` — DataFusion backend for the DataPress HTTP server.
2
3pub mod store;
4
5use std::sync::Arc;
6
7use crate::store::Store;
8use datapress_core::backend::Backend;
9use datapress_core::config::AppConfig;
10
11/// Build the dataset store, start the actix server, and run until the
12/// process receives SIGINT.
13pub async fn serve(cfg: AppConfig) -> std::io::Result<()> {
14    datapress_core::banner::print();
15    let store: Arc<dyn Backend> =
16        Arc::new(Store::load(&cfg).await.expect("failed to load datasets"));
17    datapress_core::server::serve(cfg, store, "DataFusion").await
18}
19
20/// Like [`serve`], but driven to a graceful stop by `shutdown` instead of
21/// OS signals. Used when DataPress is embedded in another runtime (the
22/// Python extension) so it doesn't install signal handlers that fight the
23/// host's.
24pub async fn serve_with_shutdown(
25    cfg: AppConfig,
26    shutdown: impl std::future::Future<Output = ()> + Send + 'static,
27) -> std::io::Result<()> {
28    datapress_core::banner::print();
29    let store: Arc<dyn Backend> =
30        Arc::new(Store::load(&cfg).await.expect("failed to load datasets"));
31    datapress_core::server::serve_with_shutdown(cfg, store, "DataFusion", shutdown).await
32}