ecli_server_codegen/
lib.rs

1#![allow(
2    missing_docs,
3    trivial_casts,
4    unused_variables,
5    unused_mut,
6    unused_imports,
7    unused_extern_crates,
8    non_camel_case_types
9)]
10#![allow(unused_imports, unused_attributes)]
11#![allow(clippy::derive_partial_eq_without_eq, clippy::blacklisted_name)]
12
13use async_trait::async_trait;
14use futures::Stream;
15use serde::{Deserialize, Serialize};
16use std::error::Error;
17use std::task::{Context, Poll};
18use swagger::{ApiError, ContextWrapper};
19
20type ServiceError = Box<dyn Error + Send + Sync + 'static>;
21
22pub const BASE_PATH: &str = "";
23pub const API_VERSION: &str = "1.0.0";
24
25#[derive(Debug, PartialEq, Serialize, Deserialize)]
26pub enum GetTaskListResponse {
27    /// List of running tasks
28    ListOfRunningTasks(models::TaskListResponse),
29}
30
31#[derive(Debug, PartialEq, Serialize, Deserialize)]
32#[must_use]
33pub enum GetTaskLogByIdResponse {
34    /// Invalid handle
35    InvalidHandle(models::GeneralError),
36    /// The log fetched
37    TheLogFetched(Vec<models::GetTaskLogResponseInner>),
38}
39
40#[derive(Debug, PartialEq, Serialize, Deserialize)]
41#[must_use]
42pub enum PauseTaskByIdResponse {
43    /// Failed to pause
44    FailedToPause(models::GeneralError),
45    /// Invalid handle
46    InvalidHandle(models::GeneralError),
47    /// Status of pausing the task
48    StatusOfPausingTheTask(models::TaskStatus),
49}
50
51#[derive(Debug, PartialEq, Serialize, Deserialize)]
52#[must_use]
53pub enum ResumeTaskByIdResponse {
54    /// Failed to resume
55    FailedToResume(models::GeneralError),
56    /// Invalid handle
57    InvalidHandle(models::GeneralError),
58    /// Status of the task
59    StatusOfTheTask(models::TaskStatus),
60}
61
62#[derive(Debug, PartialEq, Serialize, Deserialize)]
63#[must_use]
64pub enum StartTaskResponse {
65    /// Invalid arguments
66    InvalidArguments(models::GeneralError),
67    /// List of running tasks
68    ListOfRunningTasks(models::StartTask200Response),
69}
70
71#[derive(Debug, PartialEq, Serialize, Deserialize)]
72#[must_use]
73pub enum StopTaskByIdResponse {
74    /// Status of stopping the task
75    StatusOfStoppingTheTask(serde_json::Value),
76    /// Invalid handle
77    InvalidHandle(models::GeneralError),
78    /// Failed to terminate
79    FailedToTerminate(models::GeneralError),
80}
81
82/// API
83#[async_trait]
84#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
85pub trait Api<C: Send + Sync> {
86    fn poll_ready(
87        &self,
88        _cx: &mut Context,
89    ) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>> {
90        Poll::Ready(Ok(()))
91    }
92
93    /// Get list of running tasks
94    async fn get_task_list(&self, context: &C) -> Result<GetTaskListResponse, ApiError>;
95
96    /// get log
97    async fn get_task_log_by_id(
98        &self,
99        get_task_log_request: models::GetTaskLogRequest,
100        context: &C,
101    ) -> Result<GetTaskLogByIdResponse, ApiError>;
102
103    /// Pause a task by id
104    async fn pause_task_by_id(
105        &self,
106        simple_id_request: models::SimpleIdRequest,
107        context: &C,
108    ) -> Result<PauseTaskByIdResponse, ApiError>;
109
110    /// Resume a task by id
111    async fn resume_task_by_id(
112        &self,
113        simple_id_request: models::SimpleIdRequest,
114        context: &C,
115    ) -> Result<ResumeTaskByIdResponse, ApiError>;
116
117    /// Start a new task
118    async fn start_task(
119        &self,
120        start_task_request: models::StartTaskRequest,
121        context: &C,
122    ) -> Result<StartTaskResponse, ApiError>;
123
124    /// Stop a task by id
125    async fn stop_task_by_id(
126        &self,
127        simple_id_request: models::SimpleIdRequest,
128        context: &C,
129    ) -> Result<StopTaskByIdResponse, ApiError>;
130}
131
132/// API where `Context` isn't passed on every API call
133#[async_trait]
134#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
135pub trait ApiNoContext<C: Send + Sync> {
136    fn poll_ready(
137        &self,
138        _cx: &mut Context,
139    ) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>>;
140
141    fn context(&self) -> &C;
142
143    /// Get list of running tasks
144    async fn get_task_list(&self) -> Result<GetTaskListResponse, ApiError>;
145
146    /// get log
147    async fn get_task_log_by_id(
148        &self,
149        get_task_log_request: models::GetTaskLogRequest,
150    ) -> Result<GetTaskLogByIdResponse, ApiError>;
151
152    /// Pause a task by id
153    async fn pause_task_by_id(
154        &self,
155        simple_id_request: models::SimpleIdRequest,
156    ) -> Result<PauseTaskByIdResponse, ApiError>;
157
158    /// Resume a task by id
159    async fn resume_task_by_id(
160        &self,
161        simple_id_request: models::SimpleIdRequest,
162    ) -> Result<ResumeTaskByIdResponse, ApiError>;
163
164    /// Start a new task
165    async fn start_task(
166        &self,
167        start_task_request: models::StartTaskRequest,
168    ) -> Result<StartTaskResponse, ApiError>;
169
170    /// Stop a task by id
171    async fn stop_task_by_id(
172        &self,
173        simple_id_request: models::SimpleIdRequest,
174    ) -> Result<StopTaskByIdResponse, ApiError>;
175}
176
177/// Trait to extend an API to make it easy to bind it to a context.
178pub trait ContextWrapperExt<C: Send + Sync>
179where
180    Self: Sized,
181{
182    /// Binds this API to a context.
183    fn with_context(self, context: C) -> ContextWrapper<Self, C>;
184}
185
186impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ContextWrapperExt<C> for T {
187    fn with_context(self: T, context: C) -> ContextWrapper<T, C> {
188        ContextWrapper::<T, C>::new(self, context)
189    }
190}
191
192#[async_trait]
193impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for ContextWrapper<T, C> {
194    fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), ServiceError>> {
195        self.api().poll_ready(cx)
196    }
197
198    fn context(&self) -> &C {
199        ContextWrapper::context(self)
200    }
201
202    /// Get list of running tasks
203    async fn get_task_list(&self) -> Result<GetTaskListResponse, ApiError> {
204        let context = self.context().clone();
205        self.api().get_task_list(&context).await
206    }
207
208    /// get log
209    async fn get_task_log_by_id(
210        &self,
211        get_task_log_request: models::GetTaskLogRequest,
212    ) -> Result<GetTaskLogByIdResponse, ApiError> {
213        let context = self.context().clone();
214        self.api()
215            .get_task_log_by_id(get_task_log_request, &context)
216            .await
217    }
218
219    /// Pause a task by id
220    async fn pause_task_by_id(
221        &self,
222        simple_id_request: models::SimpleIdRequest,
223    ) -> Result<PauseTaskByIdResponse, ApiError> {
224        let context = self.context().clone();
225        self.api()
226            .pause_task_by_id(simple_id_request, &context)
227            .await
228    }
229
230    /// Resume a task by id
231    async fn resume_task_by_id(
232        &self,
233        simple_id_request: models::SimpleIdRequest,
234    ) -> Result<ResumeTaskByIdResponse, ApiError> {
235        let context = self.context().clone();
236        self.api()
237            .resume_task_by_id(simple_id_request, &context)
238            .await
239    }
240
241    /// Start a new task
242    async fn start_task(
243        &self,
244        start_task_request: models::StartTaskRequest,
245    ) -> Result<StartTaskResponse, ApiError> {
246        let context = self.context().clone();
247        self.api().start_task(start_task_request, &context).await
248    }
249
250    /// Stop a task by id
251    async fn stop_task_by_id(
252        &self,
253        simple_id_request: models::SimpleIdRequest,
254    ) -> Result<StopTaskByIdResponse, ApiError> {
255        let context = self.context().clone();
256        self.api()
257            .stop_task_by_id(simple_id_request, &context)
258            .await
259    }
260}
261
262#[cfg(feature = "client")]
263pub mod client;
264
265// Re-export Client as a top-level name
266#[cfg(feature = "client")]
267pub use client::Client;
268
269#[cfg(feature = "server")]
270pub mod server;
271
272// Re-export router() as a top-level name
273#[cfg(feature = "server")]
274pub use self::server::Service;
275
276#[cfg(feature = "server")]
277pub mod context;
278
279pub mod models;
280
281#[cfg(any(feature = "client", feature = "server"))]
282pub(crate) mod header;