use apify_client::{ApifyClient, LogOptions};
use futures_util::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = std::env::var("APIFY_TOKEN").expect("set APIFY_TOKEN");
let client = ApifyClient::new(token);
let run = client
.actor("apify/hello-world")
.call::<serde_json::Value>(None, Default::default(), Some(120))
.await?;
println!("Run {} finished with status {:?}", run.id, run.status);
let raw_log = client
.run(&run.id)
.log()
.get_with_options(LogOptions { raw: Some(true) })
.await?;
match raw_log {
Some(log) => println!("Fetched raw log ({} bytes)", log.len()),
None => println!("Run has no log"),
}
let mut stream = client
.run(&run.id)
.get_streamed_log_with_options(LogOptions { raw: Some(true) })
.await?;
let mut streamed_bytes = 0usize;
while let Some(chunk) = stream.next().await {
streamed_bytes += chunk?.len();
}
println!("Streamed raw log ({streamed_bytes} bytes)");
Ok(())
}