From 101577a7847fd9256d801f42c567699cdee91099 Mon Sep 17 00:00:00 2001 From: Noor Date: Mon, 16 Dec 2024 11:42:05 +0530 Subject: [PATCH] Restart Policy add RestartPolicy message and integrate into ChildProcess configuration on both proto and rust structs --- proto/manager_protobuf.proto | 10 ++++++++++ src/lib.rs | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/proto/manager_protobuf.proto b/proto/manager_protobuf.proto index 3d55b24..fc5bb24 100644 --- a/proto/manager_protobuf.proto +++ b/proto/manager_protobuf.proto @@ -30,10 +30,20 @@ message EnvironmentEntry { string value = 2; } +message RestartPolicy { + uint32 max_retries = 1; + uint32 delay_seconds = 2; + oneof policy { + bool ALWAYS = 3; + bool ON_NON_ZERO_EXIT = 4; + } +} + // Represents a child process configuration message ChildProcess { string path = 1; repeated string arguments = 2; + RestartPolicy restart_policy = 3; } service ConfigManager { diff --git a/src/lib.rs b/src/lib.rs index 180d0fb..25c7ee2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,23 @@ pub mod config { #[prost(string, tag = "2")] pub value: String, } + #[derive(Clone, Serialize, Deserialize, prost::Message)] + pub struct RestartPolicy { + #[prost(uint32, tag = "1")] + max_retries: u32, + #[prost(uint32, tag = "2")] + delay_seconds: u32, + #[prost(oneof = "RestartPolicyType", tags = "3, 4")] + policy: Option, + } + + #[derive(Clone, Serialize, Deserialize, prost::Oneof)] + pub enum RestartPolicyType { + #[prost(bool, tag = "3")] + Always(bool), + #[prost(bool, tag = "4")] + OnNonZeroExit(bool), + } #[derive(Clone, Serialize, Deserialize, prost::Message)] pub struct ChildProcess { @@ -40,6 +57,8 @@ pub mod config { pub path: String, #[prost(string, repeated, tag = "2")] pub arguments: Vec, + #[prost(message, optional, tag = "3")] + restart_policy: Option, } #[derive(Clone, Serialize, Deserialize, prost::Message)]