Skip to content

Commit

Permalink
add announce-exit call for workers (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
trusch authored Jan 8, 2025
1 parent 5c0fb6c commit 51472ee
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/commands/workers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gevulot_rs::builders::{ByteSize, ByteUnit, MsgCreateWorkerBuilder, MsgDeleteWorkerBuilder};
use gevulot_rs::builders::{ByteSize, ByteUnit, MsgAnnounceWorkerExitBuilder, MsgCreateWorkerBuilder, MsgDeleteWorkerBuilder};
use patharg::InputArg;
use serde_json::Value;
use std::path::Path;
Expand All @@ -25,6 +25,7 @@ impl Command {
create_worker(&self.chain_args, file.path_ref().map(|v| &**v)).await
}
Subcommand::Delete { id } => delete_worker(&self.chain_args, id).await,
Subcommand::AnnounceExit { id } => announce_worker_exit(&self.chain_args, id).await,
}?;
print_object(format, &value)
}
Expand Down Expand Up @@ -54,6 +55,12 @@ enum Subcommand {
/// The ID of the worker to delete.
id: String,
},

/// Announce a worker's exit.
AnnounceExit {
/// The ID of the worker to announce exit.
id: String,
},
}

/// Lists all workers.
Expand Down Expand Up @@ -142,3 +149,30 @@ async fn delete_worker(
"message": format!("Worker {} deleted successfully", worker_id)
}))
}

async fn announce_worker_exit(
chain_args: &ChainArgs,
worker_id: &str,
) -> Result<Value, Box<dyn std::error::Error>> {
let mut client = connect_to_gevulot(chain_args).await?;
let me = client
.base_client
.write()
.await
.address
.clone()
.ok_or("No address found, did you set a mnemonic?")?;
client
.workers
.announce_exit(
MsgAnnounceWorkerExitBuilder::default()
.creator(me)
.worker_id(worker_id.to_string())
.into_message()?,
)
.await?;
Ok(serde_json::json!({
"status": "success",
"message": format!("Worker {} announced exit successfully", worker_id)
}))
}

0 comments on commit 51472ee

Please sign in to comment.