Created
November 4, 2025 05:56
-
-
Save kevinmingtarja/b16ece61b96f5c2966278e8ccc93c3cd to your computer and use it in GitHub Desktop.
rickle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use sqlx::sqlite::SqlitePool; | |
| use std::env; | |
| use serde_pickle::Value; | |
| #[derive(sqlx::FromRow)] | |
| struct Cluster { | |
| name: String, | |
| launched_at: Option<i64>, | |
| handle: Option<Vec<u8>>, | |
| last_use: Option<String>, | |
| status: Option<String>, | |
| autostop: Option<i64>, | |
| to_down: Option<i64>, | |
| metadata: Option<String>, | |
| owner: Option<String>, | |
| cluster_hash: Option<String>, | |
| storage_mounts_metadata: Option<Vec<u8>>, | |
| cluster_ever_up: Option<i64>, | |
| status_updated_at: Option<i64>, | |
| config_hash: Option<String>, | |
| user_hash: Option<String>, | |
| workspace: Option<String>, | |
| last_creation_yaml: Option<String>, | |
| last_creation_command: Option<String>, | |
| is_managed: Option<i64>, | |
| provision_log_path: Option<String>, | |
| skylet_ssh_tunnel_metadata: Option<Vec<u8>>, | |
| } | |
| // #[derive(Debug, Deserialize)] | |
| // struct Handle { | |
| // cluster_name: String, | |
| // cluster_name_on_cloud: String, | |
| // cluster_yaml: Option<String>, | |
| // launched_nodes: Option<i32>, | |
| // } | |
| #[tokio::main(flavor = "current_thread")] | |
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| let conn = SqlitePool::connect(&env::var("DATABASE_URL")?).await?; | |
| let clusters = get_clusters(&conn).await?; | |
| for cluster in clusters { | |
| println!("Cluster: {}", cluster.name); | |
| println!("User Hash: {:?}", cluster.user_hash); | |
| println!("Status: {:?}", cluster.status); | |
| // Deserialize the pickled handle | |
| if let Some(handle_bytes) = &cluster.handle { | |
| match serde_pickle::from_slice::<Value>(handle_bytes, Default::default()) { | |
| Ok(handle) => { println!("Handle: {:?}\n", handle) }, | |
| Err(e) => eprintln!(" Failed to deserialize handle: {}", e), | |
| } | |
| } | |
| } | |
| Ok(()) | |
| } | |
| async fn get_clusters(pool: &SqlitePool) -> Result<Vec<Cluster>, sqlx::Error> { | |
| let clusters = sqlx::query_as!(Cluster, | |
| r#" | |
| SELECT name, launched_at, handle, last_use, status, autostop, to_down, | |
| metadata, owner, cluster_hash, storage_mounts_metadata, cluster_ever_up, | |
| status_updated_at, config_hash, user_hash, workspace, last_creation_yaml, | |
| last_creation_command, is_managed, provision_log_path, skylet_ssh_tunnel_metadata | |
| FROM clusters | |
| "# | |
| ) | |
| .fetch_all(pool) | |
| .await?; | |
| Ok(clusters) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment