forked from Azure/azure-sdk-for-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_task.rs
42 lines (34 loc) · 1.55 KB
/
create_task.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Creates a batch job and task using the data plane APIs
cargo run --package azure_svc_batch --example create_task
*/
use azure_identity::AzureCliCredential;
use azure_svc_batch::models::{JobAddParameter, PoolInformation, TaskAddParameter};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let account_name = std::env::args().nth(1).expect("please specify batch account");
let region = std::env::args().nth(2).expect("please specify region");
let pool_id = std::env::args().nth(3).expect("please specify pool");
let job_id = std::env::args().nth(4).expect("please specify job_id");
let task_id = std::env::args().nth(5).expect("please specify task_id");
let endpoint = azure_core::Url::parse(&format!("https://{account_name}.{region}.batch.azure.com"))?;
let scopes = &["https://batch.core.windows.net/.default"];
let credential = Arc::new(AzureCliCredential::new());
let client = azure_svc_batch::Client::builder(credential)
.endpoint(endpoint)
.scopes(scopes)
.build()?;
let pool_info = PoolInformation {
pool_id: Some(pool_id),
..PoolInformation::new()
};
println!("creating job");
let job_params = JobAddParameter::new(job_id.clone(), pool_info);
client.job_client().add(job_params).send().await?;
println!("creating task");
let command_line = "echo hello there".to_string();
let task = TaskAddParameter::new(task_id.to_string(), command_line);
client.task_client().add(job_id, task).send().await?;
Ok(())
}