Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cdec1fb
Initial outline of backup/restore
tpoliaw Aug 19, 2026
9df360d
Update Rust crate tokio to v1.53.1 (#288)
renovate[bot] Aug 24, 2026
2378481
Update Rust crate sqlx to 0.9.0 (#284)
renovate[bot] Aug 24, 2026
9141e47
Update rust Docker tag to v1.98.0 (#285)
renovate[bot] Aug 24, 2026
227cf7c
Update tracing and telemetry (#282)
renovate[bot] Aug 24, 2026
bb84deb
Update patches (#289)
renovate[bot] Aug 24, 2026
f0146a5
add transaction to insert configurations function
shree-iyengar-dls Sep 2, 2026
4eaa682
add serialisable data transfer object
shree-iyengar-dls Sep 2, 2026
9ed6047
Add prek configuration to check linting prior to CI (#296)
tpoliaw Sep 3, 2026
963d3cb
add force clear and exisiting configs check to transaction
shree-iyengar-dls Sep 3, 2026
3d52581
Remove async-std dependency (#300)
tpoliaw Sep 3, 2026
6f2341a
patch up compiler errors
tpoliaw Sep 3, 2026
ed4f11a
add restore handler
shree-iyengar-dls Sep 3, 2026
d014c4e
resolve merge commit
shree-iyengar-dls Sep 3, 2026
720de15
add serialise deserialise to instrumentconfiguration
shree-iyengar-dls Sep 4, 2026
1fc4e34
Initial outline of backup/restore
tpoliaw Aug 19, 2026
ec78f00
add transaction to insert configurations function
shree-iyengar-dls Sep 2, 2026
c9414c5
add serialisable data transfer object
shree-iyengar-dls Sep 2, 2026
ccd6519
add force clear and exisiting configs check to transaction
shree-iyengar-dls Sep 3, 2026
6708953
add restore handler
shree-iyengar-dls Sep 3, 2026
76adde8
rebase
shree-iyengar-dls Sep 4, 2026
f137f21
add serialise deserialise to instrumentconfiguration
shree-iyengar-dls Sep 4, 2026
e57ad44
merge remote branch in
shree-iyengar-dls Sep 4, 2026
e62f7f7
remove rebase noise
shree-iyengar-dls Sep 4, 2026
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
36 changes: 36 additions & 0 deletions src/db_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,42 @@ impl SqliteScanPathService {
.collect())
}

pub async fn insert_configurations(
&self,
configs: &[InstrumentConfiguration],
) -> Result<(), sqlx::Error> {
let mut tx = self.pool.begin().await?;

sqlx::query!("DelETE FROM instrument").execute(&mut tx).await?;
Comment thread
shree-iyengar-dls marked this conversation as resolved.
Outdated

for config in configs {
sqlx::query!(
"INSERT INTO instrument (name, scan_number, directory, scan, detector, tracker_file_extension) VALUES (?, ?, ?, ?, ?, ?)",
config.name,
config.scan_number,
config.directory,
config.scan,
config.detector,
config.tracker_file_extension
)
.execute(&mut tx)
.await?;
}

tx.commit().await?;
Ok(())
}
}
pub async fn next_scan_configuration(
&self,
instrument: &str,
current_high: Option<u32>,
) -> Result<InstrumentConfiguration, ConfigurationError> {
let exp = current_high.unwrap_or(0);
query_as!(
DbInstrumentConfig,
}

pub async fn next_scan_configuration(
&self,
instrument: &str,
Expand Down
11 changes: 10 additions & 1 deletion src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use async_graphql::{
};
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use auth::{AuthError, PolicyCheck};
use axum::extract::State;
use axum::http::StatusCode;
use axum::response::{Html, IntoResponse};
use axum::routing::{get, post};
Expand Down Expand Up @@ -67,14 +68,16 @@ pub async fn serve_graphql(opts: ServeOptions) {
let schema = Schema::build(Query, Mutation, EmptySubscription)
.extension(Tracing)
.limit_directives(32)
.data(db)
.data(db.clone())
.data(directory_numtracker)
.data(opts.policy.map(PolicyCheck::new))
.finish();
let app = Router::new()
// status check endpoint allows external processes to monitor status of server without
// making graphql queries
.route("/status", get(server_status))
.route("/admin/export", get(export_handler))
// .route("/admin/restore", post(restore_handler))
.route("/graphql", post(graphql_handler))
// make it obvious that /graphql isn't expected to work when visiting from a browser
.route(
Expand All @@ -88,6 +91,7 @@ pub async fn serve_graphql(opts: ServeOptions) {
// Interactive graphiql playground
.route("/graphiql", get(graphiql))
// Make it look less like something is broken when going to any other page
.with_state(db)
.fallback((
StatusCode::NOT_FOUND,
Html(include_str!("../../static/404.html")),
Expand All @@ -102,6 +106,11 @@ pub async fn serve_graphql(opts: ServeOptions) {
.expect("Can't serve graphql endpoint");
}

async fn export_handler(State(db): State<SqliteScanPathService>) -> String {
let configs = db.all_configurations().await;
return format!("{configs:?}");
}

async fn create_signal_handler() {
let mut term = signal(SignalKind::terminate()).expect("Failed to create SIGTERM listener");
let mut int = signal(SignalKind::interrupt()).expect("Failed to create SIGINT listener");
Expand Down
Loading