Skip to main content

harmos_sdk/
services.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14pub use harmos_domain::model::services::policy::{RestartPolicy, ServicePolicy};
15
16/* === Imports === */
17
18// Standard Library Imports
19use std::future::Future;
20
21// Third Party Imports
22
23// Local Imports
24use crate::operations::ExecutionContext;
25
26/* === Constants === */
27
28/* === Macros === */
29
30/* === Type Aliases === */
31
32/* === Structs === */
33
34/* === Enums === */
35
36/* === Traits === */
37
38pub trait Service: Send + Sized + 'static {
39    type Error: std::error::Error + Send + Sync + 'static;
40
41    fn initialize(context: ExecutionContext) -> impl Future<Output = Result<Self, Self::Error>> + Send;
42    fn run(&mut self, context: ExecutionContext) -> impl Future<Output = Result<(), Self::Error>> + Send;
43
44    fn stop(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send {
45        async { Ok(()) }
46    }
47    fn cleanup(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send {
48        async { Ok(()) }
49    }
50}
51
52/* === Implementations === */
53
54/* === Public Functions === */
55
56/* === Private Functions === */
57
58/* === Tests === */