From 64e0d7af9f0a6b645313339588b9d24e1a9571ce Mon Sep 17 00:00:00 2001 From: Jonathan Baecker Date: Tue, 15 Oct 2024 11:47:45 +0200 Subject: [PATCH] wait for control job to be done --- engine/src/api/routes.rs | 16 ++++++++++++++-- engine/src/utils/control.rs | 2 +- frontend/stores/config.ts | 1 - 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/engine/src/api/routes.rs b/engine/src/api/routes.rs index 0780067f..978f87eb 100644 --- a/engine/src/api/routes.rs +++ b/engine/src/api/routes.rs @@ -869,10 +869,22 @@ pub async fn control_playout( ) -> Result { let manager = controllers.lock().unwrap().get(*id).unwrap(); - match control_state(&pool, manager, &control.control).await { + if manager.is_processing.load(Ordering::SeqCst) { + return Err(ServiceError::Conflict( + "A command is already being processed, please wait".to_string(), + )); + } + + manager.is_processing.store(true, Ordering::SeqCst); + + let resp = match control_state(&pool, &manager, &control.control).await { Ok(res) => Ok(web::Json(res)), Err(e) => Err(e), - } + }; + + manager.is_processing.store(false, Ordering::SeqCst); + + resp } /// **Get current Clip** diff --git a/engine/src/utils/control.rs b/engine/src/utils/control.rs index 70cb39cb..212846fc 100644 --- a/engine/src/utils/control.rs +++ b/engine/src/utils/control.rs @@ -132,7 +132,7 @@ pub async fn send_message( pub async fn control_state( conn: &Pool, - manager: ChannelManager, + manager: &ChannelManager, command: &str, ) -> Result, ServiceError> { let config = manager.config.lock().unwrap().clone(); diff --git a/frontend/stores/config.ts b/frontend/stores/config.ts index 92157609..2aa925bd 100644 --- a/frontend/stores/config.ts +++ b/frontend/stores/config.ts @@ -2,7 +2,6 @@ import { cloneDeep } from 'lodash-es' import { defineStore } from 'pinia' import type { AdvancedConfig } from '~/types/advanced_config' - export const useConfig = defineStore('config', { state: () => ({ i: 0,