use std::sync::Arc;
use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::manager_api as api;
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};
pub struct SessionsResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl SessionsResource {
pub async fn create(&self) -> Result<models::SessionResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::create_session(self.cfg.as_ref())
})
.await
.map_err(map_manager_err)
}
pub async fn get(&self, id: &str) -> Result<models::SessionResponse, ManagerError> {
with_retry(&self.retry, true, || {
api::get_session_variables(self.cfg.as_ref(), id)
})
.await
.map_err(map_manager_err)
}
pub async fn update_variables(
&self,
id: &str,
variables: std::collections::HashMap<String, serde_json::Value>,
) -> Result<models::SessionResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::update_session_variables(self.cfg.as_ref(), id, Some(variables.clone()))
})
.await
.map_err(map_manager_err)
}
}