diff options
| author | soryu <soryu@soryu.co> | 2026-02-01 02:00:32 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-01 02:00:32 +0000 |
| commit | 158337a6c55b0e8b7fdaf7ae4e6086a11b7b906f (patch) | |
| tree | 3676d9629c9a46d19d4881b7f7a91de91b7d7a91 /makima/src/daemon/api | |
| parent | 7567153e6281b94e39e52be5d060b381ed69597d (diff) | |
| download | soryu-158337a6c55b0e8b7fdaf7ae4e6086a11b7b906f.tar.gz soryu-158337a6c55b0e8b7fdaf7ae4e6086a11b7b906f.zip | |
[WIP] Heartbeat checkpoint - 2026-02-01 02:00:32 UTCmakima/task-task-5f420783-5f420783
Diffstat (limited to 'makima/src/daemon/api')
| -rw-r--r-- | makima/src/daemon/api/contract.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/makima/src/daemon/api/contract.rs b/makima/src/daemon/api/contract.rs index 7c76b40..b6da837 100644 --- a/makima/src/daemon/api/contract.rs +++ b/makima/src/daemon/api/contract.rs @@ -274,6 +274,7 @@ impl ApiClient { } } +/// Request to add a remote repository. #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct AddRemoteRepositoryRequest { @@ -281,3 +282,91 @@ struct AddRemoteRepositoryRequest { repository_url: String, is_primary: bool, } + +// ============================================================================= +// Contract Management Helper API Methods +// ============================================================================= + +/// Request to pause a contract. +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PauseContractRequest { + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<String>, +} + +/// Request to change contract phase. +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +pub struct ChangePhaseRequest { + pub phase: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub confirmed: Option<bool>, +} + +/// Request to update contract status. +#[derive(Serialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct UpdateContractStatusRequest { + #[serde(skip_serializing_if = "Option::is_none")] + pub status: Option<String>, + #[serde(skip_serializing_if = "Option::is_none")] + pub pause_reason: Option<String>, +} + +impl ApiClient { + /// Pause a contract by setting its status to paused. + pub async fn pause_contract( + &self, + contract_id: Uuid, + reason: Option<String>, + ) -> Result<JsonValue, ApiError> { + let req = UpdateContractStatusRequest { + status: Some("paused".to_string()), + pause_reason: reason, + }; + self.put(&format!("/api/v1/contracts/{}", contract_id), &req) + .await + } + + /// Resume a paused contract by setting its status back to active. + pub async fn resume_contract(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> { + let req = UpdateContractStatusRequest { + status: Some("active".to_string()), + pause_reason: None, + }; + self.put(&format!("/api/v1/contracts/{}", contract_id), &req) + .await + } + + /// Advance a contract to a specific phase. + pub async fn advance_contract_phase( + &self, + contract_id: Uuid, + phase: &str, + force: bool, + ) -> Result<JsonValue, ApiError> { + let req = ChangePhaseRequest { + phase: phase.to_string(), + confirmed: Some(force), + }; + self.post(&format!("/api/v1/contracts/{}/phase", contract_id), &req) + .await + } + + /// Request a supervisor restart for a contract. + /// This will stop the current supervisor (if running) and queue a new one. + pub async fn restart_supervisor(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> { + self.post_empty(&format!( + "/api/v1/contracts/{}/supervisor/restart", + contract_id + )) + .await + } + + /// Get detailed contract information including health status. + pub async fn get_contract_health(&self, contract_id: Uuid) -> Result<JsonValue, ApiError> { + self.get(&format!("/api/v1/contracts/{}/health", contract_id)) + .await + } +} |
