tape: use worker task for eject-media api
This commit is contained in:
		| @ -296,13 +296,30 @@ pub fn rewind( | |||||||
|             }, |             }, | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
|  |     returns: { | ||||||
|  |         schema: UPID_SCHEMA, | ||||||
|  |     }, | ||||||
| )] | )] | ||||||
| /// Eject/Unload drive media | /// Eject/Unload drive media | ||||||
| pub async fn eject_media(drive: String) -> Result<(), Error> { | pub fn eject_media( | ||||||
|  |     drive: String, | ||||||
|  |     rpcenv: &mut dyn RpcEnvironment, | ||||||
|  | ) -> Result<Value, Error> { | ||||||
|  |  | ||||||
|     let (config, _digest) = config::drive::config()?; |     let (config, _digest) = config::drive::config()?; | ||||||
|  |  | ||||||
|     tokio::task::spawn_blocking(move || { |     check_drive_exists(&config, &drive)?; // early check before starting worker | ||||||
|  |  | ||||||
|  |     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; | ||||||
|  |  | ||||||
|  |     let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; | ||||||
|  |  | ||||||
|  |     let upid_str = WorkerTask::new_thread( | ||||||
|  |         "eject-media", | ||||||
|  |         Some(drive.clone()), | ||||||
|  |         auth_id, | ||||||
|  |         to_stdout, | ||||||
|  |         move |_worker| { | ||||||
|             if let Some((mut changer, _)) = media_changer(&config, &drive)? { |             if let Some((mut changer, _)) = media_changer(&config, &drive)? { | ||||||
|                 changer.unload_media(None)?; |                 changer.unload_media(None)?; | ||||||
|             } else { |             } else { | ||||||
| @ -310,7 +327,9 @@ pub async fn eject_media(drive: String) -> Result<(), Error> { | |||||||
|                 drive.eject_media()?; |                 drive.eject_media()?; | ||||||
|             } |             } | ||||||
|             Ok(()) |             Ok(()) | ||||||
|     }).await? |         })?; | ||||||
|  |  | ||||||
|  |     Ok(upid_str.into()) | ||||||
| } | } | ||||||
|  |  | ||||||
| #[api( | #[api( | ||||||
| @ -1176,7 +1195,7 @@ pub const SUBDIRS: SubdirMap = &sorted!([ | |||||||
|     ( |     ( | ||||||
|         "eject-media", |         "eject-media", | ||||||
|         &Router::new() |         &Router::new() | ||||||
|             .put(&API_METHOD_EJECT_MEDIA) |             .post(&API_METHOD_EJECT_MEDIA) | ||||||
|     ), |     ), | ||||||
|     ( |     ( | ||||||
|         "erase-media", |         "erase-media", | ||||||
|  | |||||||
| @ -204,25 +204,28 @@ async fn rewind(param: Value) -> Result<(), Error> { | |||||||
|                 schema: DRIVE_NAME_SCHEMA, |                 schema: DRIVE_NAME_SCHEMA, | ||||||
|                 optional: true, |                 optional: true, | ||||||
|             }, |             }, | ||||||
|  |             "output-format": { | ||||||
|  |                 schema: OUTPUT_FORMAT, | ||||||
|  |                 optional: true, | ||||||
|  |             }, | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
| )] | )] | ||||||
| /// Eject/Unload drive media | /// Eject/Unload drive media | ||||||
| async fn eject_media( | async fn eject_media(param: Value) -> Result<(), Error> { | ||||||
|     mut param: Value, |  | ||||||
|     rpcenv: &mut dyn RpcEnvironment, |     let output_format = get_output_format(¶m); | ||||||
| ) -> Result<(), Error> { |  | ||||||
|  |  | ||||||
|     let (config, _digest) = config::drive::config()?; |     let (config, _digest) = config::drive::config()?; | ||||||
|  |  | ||||||
|     param["drive"] = lookup_drive_name(¶m, &config)?.into(); |     let drive = lookup_drive_name(¶m, &config)?; | ||||||
|  |  | ||||||
|     let info = &api2::tape::drive::API_METHOD_EJECT_MEDIA; |     let mut client = connect_to_localhost()?; | ||||||
|  |  | ||||||
|     match info.handler { |     let path = format!("api2/json/tape/drive/{}/eject-media", drive); | ||||||
|         ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?, |     let result = client.post(&path, Some(param)).await?; | ||||||
|         _ => unreachable!(), |  | ||||||
|     }; |     view_task_result(client, result, &output_format).await?; | ||||||
|  |  | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
|  | |||||||
| @ -279,6 +279,7 @@ Ext.define('PBS.Utils', { | |||||||
| 	    "barcode-label-media": [gettext('Drive'), gettext('Barcode label media')], | 	    "barcode-label-media": [gettext('Drive'), gettext('Barcode label media')], | ||||||
| 	    dircreate: [gettext('Directory Storage'), gettext('Create')], | 	    dircreate: [gettext('Directory Storage'), gettext('Create')], | ||||||
| 	    dirremove: [gettext('Directory'), gettext('Remove')], | 	    dirremove: [gettext('Directory'), gettext('Remove')], | ||||||
|  | 	    "eject-media": [gettext('Drive'), gettext('Eject media')], | ||||||
| 	    "erase-media": [gettext('Drive'), gettext('Erase media')], | 	    "erase-media": [gettext('Drive'), gettext('Erase media')], | ||||||
| 	    garbage_collection: ['Datastore', gettext('Garbage collect')], | 	    garbage_collection: ['Datastore', gettext('Garbage collect')], | ||||||
| 	    "inventory-update": [gettext('Drive'), gettext('Inventory update')], | 	    "inventory-update": [gettext('Drive'), gettext('Inventory update')], | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user