@@ -11,18 +11,15 @@ use crate::{
1111 config:: { ComputePlatform , Config } ,
1212 cscs:: {
1313 api_client:: {
14- client:: CscsApi ,
14+ client:: { CscsApi , JobStartOptions } ,
1515 types:: { FileStat , FileSystemType , Job , JobDetail , PathEntry , PathType , S3Upload , System , UserInfo } ,
1616 } ,
1717 oauth2:: {
1818 CLIENT_ID_SECRET_NAME , CLIENT_SECRET_SECRET_NAME , client_credentials_login, finish_cscs_device_login,
1919 start_cscs_device_login,
2020 } ,
2121 } ,
22- util:: {
23- keyring:: { Secret , get_secret, store_secret} ,
24- types:: DockerImageUrl ,
25- } ,
22+ util:: keyring:: { Secret , get_secret, store_secret} ,
2623} ;
2724
2825const CSCS_MAX_DIRECT_SIZE : usize = 5242880 ;
@@ -169,12 +166,7 @@ pub async fn cscs_job_cancel(job_id: i64, system: Option<String>, platform: Opti
169166#[ allow( clippy:: too_many_arguments) ]
170167pub async fn cscs_start_job (
171168 name : Option < String > ,
172- script_file : Option < PathBuf > ,
173- image : Option < DockerImageUrl > ,
174- command : Option < Vec < String > > ,
175- container_workdir : Option < String > ,
176- env : Vec < ( String , String ) > ,
177- mount : Vec < ( String , String ) > ,
169+ options : JobStartOptions ,
178170 system : Option < String > ,
179171 platform : Option < ComputePlatform > ,
180172 account : Option < String > ,
@@ -202,12 +194,15 @@ pub async fn cscs_start_job(
202194 return Err ( eyre ! ( "couldn't get system description for {}" , current_system) ) ;
203195 }
204196 } ;
205- let container_workdir = container_workdir. unwrap_or ( config. cscs . workdir . unwrap_or ( "/scratch" . to_owned ( ) ) ) ;
197+ let container_workdir = options
198+ . container_workdir
199+ . clone ( )
200+ . unwrap_or ( config. cscs . workdir . unwrap_or ( "/scratch" . to_owned ( ) ) ) ;
206201 let base_path = scratch. join ( user_info. name . clone ( ) ) . join ( & job_name) ;
207202
208203 let mut envvars = config. cscs . env . clone ( ) ;
209- envvars. extend ( env) ;
210- let mut mount: HashMap < String , String > = mount. into_iter ( ) . collect ( ) ;
204+ envvars. extend ( options . env . clone ( ) ) ;
205+ let mut mount: HashMap < String , String > = options . mount . clone ( ) . into_iter ( ) . collect ( ) ;
211206 mount. entry ( "${SCRATCH}" . to_owned ( ) ) . or_insert ( "/scratch" . to_owned ( ) ) ;
212207
213208 let mut tera = tera:: Tera :: default ( ) ;
@@ -216,7 +211,7 @@ pub async fn cscs_start_job(
216211 let environment_template = config. cscs . edf_file_template ;
217212 tera. add_raw_template ( "environment.toml" , & environment_template) ?;
218213
219- let docker_image = image. unwrap_or ( config. cscs . image . try_into ( ) ?) ;
214+ let docker_image = options . image . clone ( ) . unwrap_or ( config. cscs . image . try_into ( ) ?) ;
220215 let meta = docker_image. inspect ( ) . await ?;
221216 if let Some ( system_info) = config. cscs . systems . get ( current_system) {
222217 let mut compatible = false ;
@@ -255,13 +250,18 @@ pub async fn cscs_start_job(
255250
256251 // upload script
257252 let script_path = base_path. join ( "script.sh" ) ;
258- let script_template = script_file
253+ let script_template = options
254+ . script_file
255+ . clone ( )
259256 . map ( std:: fs:: read_to_string)
260257 . unwrap_or ( Ok ( config. cscs . sbatch_script_template ) ) ?;
261258 tera. add_raw_template ( "script.sh" , & script_template) ?;
262259 let mut context = tera:: Context :: new ( ) ;
263260 context. insert ( "name" , & job_name) ;
264- context. insert ( "command" , & command. unwrap_or ( config. cscs . command ) . join ( " " ) ) ;
261+ context. insert (
262+ "command" ,
263+ & options. command . clone ( ) . unwrap_or ( config. cscs . command ) . join ( " " ) ,
264+ ) ;
265265 context. insert ( "environment_file" , & environment_path) ;
266266 context. insert ( "container_workdir" , & container_workdir) ;
267267 let script = tera. render ( "script.sh" , & context) ?;
@@ -271,7 +271,7 @@ pub async fn cscs_start_job(
271271
272272 // start job
273273 api_client
274- . start_job ( current_system, account, & job_name, script_path, envvars)
274+ . start_job ( current_system, account, & job_name, script_path, envvars, options )
275275 . await ?;
276276 Ok ( ( ) )
277277 }
0 commit comments