#![allow(
clippy::todo,
clippy::unimplemented,
clippy::panic,
clippy::unwrap_used,
clippy::expect_used,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::doc_markdown,
clippy::needless_pass_by_value,
clippy::too_many_arguments,
clippy::unused_async,
clippy::diverging_sub_expression,
clippy::no_effect_underscore_binding,
clippy::let_unit_value,
clippy::used_underscore_binding,
clippy::let_underscore_untyped,
clippy::struct_field_names,
clippy::manual_let_else,
clippy::map_unwrap_or,
clippy::redundant_pub_crate,
dead_code,
unreachable_code,
unused_assignments,
unused_mut,
unused_imports,
unused_variables
)]
use std::env;
use arcp::error::ARCPError;
use arcp::transport::MemoryTransport;
use arcp::{ARCPClient, Envelope, ErrorCode};
use serde_json::json;
type Client = ARCPClient<MemoryTransport>;
const CANCEL_DEADLINE_MS: u32 = 5_000;
async fn start_long_job(_client: &Client) -> Result<String, ARCPError> {
todo!()
}
async fn cancel_job(
_client: &Client,
_job_id: &str,
_reason: &str,
_deadline_ms: u32,
) -> Result<Envelope, ARCPError> {
todo!()
}
async fn interrupt_job(_client: &Client, _job_id: &str, _prompt: &str) -> Result<(), ARCPError> {
todo!()
}
async fn await_terminal(_client: &Client, _job_id: &str) -> Result<Envelope, ARCPError> {
todo!()
}
async fn scenario_cancel() -> Result<(), ARCPError> {
let client: Client = todo!(); let job_id = start_long_job(&client).await?;
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
let ack = cancel_job(&client, &job_id, "user_aborted", CANCEL_DEADLINE_MS).await?;
println!("cancel ack: {:?}", ack.payload);
let terminal = await_terminal(&client, &job_id).await?;
println!("terminal: {:?}", terminal.payload);
Ok(())
}
async fn scenario_interrupt() -> Result<(), ARCPError> {
let client: Client = todo!();
let job_id = start_long_job(&client).await?;
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
interrupt_job(
&client,
&job_id,
"Pause and ask before touching production tables.",
)
.await?;
let _next: Envelope = todo!();
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
match env::args().nth(1).as_deref().unwrap_or("cancel") {
"cancel" => scenario_cancel().await?,
"interrupt" => scenario_interrupt().await?,
other => {
eprintln!("unknown scenario: {other}");
std::process::exit(2);
}
}
Ok(())
}