From 873ffbf658867681a642731d8eb66d74e6ef5f69 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Tue, 26 Oct 2021 17:37:40 -0400 Subject: [PATCH 1/2] add simple `create_task` example for `azure_svc_batch` Note, this requires PR #449 to work as expected. --- services/svc/batch/examples/create_task.rs | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 services/svc/batch/examples/create_task.rs diff --git a/services/svc/batch/examples/create_task.rs b/services/svc/batch/examples/create_task.rs new file mode 100644 index 0000000000..401377b1d2 --- /dev/null +++ b/services/svc/batch/examples/create_task.rs @@ -0,0 +1,80 @@ +/* +Prints the name of pools using the data plane APIs + +cargo run --package azure_svc_batch --example create_task +*/ + +use azure_identity::token_credentials::AzureCliCredential; +use azure_svc_batch::models::{JobAddParameter, PoolInformation, TaskAddParameter}; +use azure_svc_batch::operations::{job, task}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + 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 base_path = format!("https://{}.{}.batch.azure.com", account_name, region); + + let http_client = azure_core::new_http_client(); + let token_credential = Box::new(AzureCliCredential {}); + let config = &azure_svc_batch::config(http_client, token_credential) + .base_path(base_path) + .token_credential_resource("https://batch.core.windows.net/") + .build(); + + let pool_id = Some(pool_id); + let pool_info = PoolInformation { + pool_id, + auto_pool_specification: None, + }; + + let job_params = JobAddParameter { + id: job_id.to_string(), + display_name: None, + priority: None, + max_parallel_tasks: None, + constraints: None, + job_manager_task: None, + job_preparation_task: None, + job_release_task: None, + common_environment_settings: vec![], + pool_info, + on_all_tasks_complete: None, + on_task_failure: None, + metadata: vec![], + uses_task_dependencies: None, + network_configuration: None, + }; + + println!("creating job"); + job::add(&config, &job_params, None, None, None, None).await?; + + let constraints = None; + let command_line = "echo hello there".to_string(); + let task = TaskAddParameter { + affinity_info: None, + application_package_references: vec![], + authentication_token_settings: None, + container_settings: None, + constraints, + command_line, + display_name: None, + environment_settings: vec![], + depends_on: None, + exit_conditions: None, + id: task_id.to_string(), + multi_instance_settings: None, + required_slots: None, + resource_files: vec![], + output_files: vec![], + user_identity: None, + }; + + println!("creating task"); + task::add(&config, &job_id, &task, None, None, None, None).await?; + + Ok(()) +} From 619822b77c3d952074c0f0c559567be089bfafe4 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Tue, 26 Oct 2021 22:08:49 -0400 Subject: [PATCH 2/2] update name per comment --- services/svc/batch/examples/create_task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/svc/batch/examples/create_task.rs b/services/svc/batch/examples/create_task.rs index 401377b1d2..fe9f397a9d 100644 --- a/services/svc/batch/examples/create_task.rs +++ b/services/svc/batch/examples/create_task.rs @@ -1,5 +1,5 @@ /* -Prints the name of pools using the data plane APIs +Creates a batch job and task using the data plane APIs cargo run --package azure_svc_batch --example create_task */