From 79fb3a289cc2ed1f5f69621547f65a43d0dd0045 Mon Sep 17 00:00:00 2001 From: Spijker Date: Tue, 1 Oct 2024 18:03:44 +0200 Subject: [PATCH] Added queue manager file lock, #392 --- Dockerfile | 1 + global.R | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 03a53bc..159a033 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,6 +47,7 @@ RUN install2.r --error --skipinstalled --ncpus -1 \ shinyalert \ datawizard \ shinybusy \ + filelock \ && rm -rf /tmp/downloaded_packages # install some more R pkgs (in a new layer) diff --git a/global.R b/global.R index 32d3ae3..26318e6 100644 --- a/global.R +++ b/global.R @@ -40,6 +40,7 @@ i18n$set_translation_language("nl") # here you select the default translation to # Databases (essential) library(RSQLite) library(pool) +library(filelock) # Visualisation library(leaflet) # For maps @@ -56,6 +57,7 @@ library(sf) library(logger) #log_threshold(loglevel) +# AT libraries library(samanapir) library(ATdatabase) @@ -79,8 +81,18 @@ db_script <- here::here("scripts","container_data_prep.R") system2("Rscript", db_script, wait = TRUE) # launch queue manager -qm_script <- here::here("scripts","queue_manager.R") -system2("Rscript", qm_script, wait = FALSE) + +lockfile <- file.path(get_database_dirname(), "lock") +lfres <- lock(lockfile, timeout = 1000) + +if(!is.null(lfres)) { + log_info("Starting queue manager") + qm_script <- here::here("scripts","queue_manager.R") + system2("Rscript", qm_script, wait = FALSE) +} else { + log_info("Queue manager not started") +} + # Set language and date options ==== options(encoding = "UTF-8") # Standard UTF-8 encoding