|
| 1 | +/* |
| 2 | +Creates a batch job and task using the data plane APIs |
| 3 | +
|
| 4 | +cargo run --package azure_svc_batch --example create_task |
| 5 | +*/ |
| 6 | + |
| 7 | +use azure_identity::token_credentials::AzureCliCredential; |
| 8 | +use azure_svc_batch::models::{JobAddParameter, PoolInformation, TaskAddParameter}; |
| 9 | +use azure_svc_batch::operations::{job, task}; |
| 10 | + |
| 11 | +#[tokio::main] |
| 12 | +async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 13 | + let account_name = std::env::args().nth(1).expect("please specify batch account"); |
| 14 | + let region = std::env::args().nth(2).expect("please specify region"); |
| 15 | + let pool_id = std::env::args().nth(3).expect("please specify pool"); |
| 16 | + let job_id = std::env::args().nth(4).expect("please specify job_id"); |
| 17 | + let task_id = std::env::args().nth(5).expect("please specify task_id"); |
| 18 | + |
| 19 | + let base_path = format!("https://{}.{}.batch.azure.com", account_name, region); |
| 20 | + |
| 21 | + let http_client = azure_core::new_http_client(); |
| 22 | + let token_credential = Box::new(AzureCliCredential {}); |
| 23 | + let config = &azure_svc_batch::config(http_client, token_credential) |
| 24 | + .base_path(base_path) |
| 25 | + .token_credential_resource("https://batch.core.windows.net/") |
| 26 | + .build(); |
| 27 | + |
| 28 | + let pool_id = Some(pool_id); |
| 29 | + let pool_info = PoolInformation { |
| 30 | + pool_id, |
| 31 | + auto_pool_specification: None, |
| 32 | + }; |
| 33 | + |
| 34 | + let job_params = JobAddParameter { |
| 35 | + id: job_id.to_string(), |
| 36 | + display_name: None, |
| 37 | + priority: None, |
| 38 | + max_parallel_tasks: None, |
| 39 | + constraints: None, |
| 40 | + job_manager_task: None, |
| 41 | + job_preparation_task: None, |
| 42 | + job_release_task: None, |
| 43 | + common_environment_settings: vec![], |
| 44 | + pool_info, |
| 45 | + on_all_tasks_complete: None, |
| 46 | + on_task_failure: None, |
| 47 | + metadata: vec![], |
| 48 | + uses_task_dependencies: None, |
| 49 | + network_configuration: None, |
| 50 | + }; |
| 51 | + |
| 52 | + println!("creating job"); |
| 53 | + job::add(&config, &job_params, None, None, None, None).await?; |
| 54 | + |
| 55 | + let constraints = None; |
| 56 | + let command_line = "echo hello there".to_string(); |
| 57 | + let task = TaskAddParameter { |
| 58 | + affinity_info: None, |
| 59 | + application_package_references: vec![], |
| 60 | + authentication_token_settings: None, |
| 61 | + container_settings: None, |
| 62 | + constraints, |
| 63 | + command_line, |
| 64 | + display_name: None, |
| 65 | + environment_settings: vec![], |
| 66 | + depends_on: None, |
| 67 | + exit_conditions: None, |
| 68 | + id: task_id.to_string(), |
| 69 | + multi_instance_settings: None, |
| 70 | + required_slots: None, |
| 71 | + resource_files: vec![], |
| 72 | + output_files: vec![], |
| 73 | + user_identity: None, |
| 74 | + }; |
| 75 | + |
| 76 | + println!("creating task"); |
| 77 | + task::add(&config, &job_id, &task, None, None, None, None).await?; |
| 78 | + |
| 79 | + Ok(()) |
| 80 | +} |
0 commit comments