Browse Source

parallelize polling

Jan Behrens 4 years ago
parent
commit
7a6f7dc34a
2 changed files with 14 additions and 7 deletions
  1. 3 1
      README.md
  2. 11 6
      config/docker-entrypoint.sh

+ 3 - 1
README.md

@@ -14,8 +14,10 @@ Setup builds on Ubuntu 18.04 (bionic) and starts server + polling process.
 Build & run locally:
 ```
 docker build -t sds-status-monitor .
-docker run -p 8001:80 sds-status-monitor
+docker run -p 8001:80 --name sds-status sds-status-monitor
+docker rm -f sds-status    # terminates container
 ```
 
 Runtime arguments:
 * `POLL_INTERVAL` - polling interval for background process (default: 60 seconds)
+* `POLL_SCRIPTS` - list of PHP scripts to run in parallel for polling (default: 'poll_adei_data.php poll_HV_data.php')

+ 11 - 6
config/docker-entrypoint.sh

@@ -2,15 +2,20 @@
 
 #/usr/bin/id
 
+POLL_SCRIPTS=${POLL_SCRIPTS:-"poll_adei_data.php poll_HV_data.php"}
 POLL_INTERVAL=${POLL_INTERVAL:-60}
 
 if [ ${POLL_INTERVAL} -gt 0 ]; then
-    (
-        while true; do
-            [ -f poll_data.sh ] && echo "Polling data: $(date)" && ./poll_data.sh
-            sleep ${POLL_INTERVAL}
-        done
-    ) &
+    for SCRIPT_NAME in ${POLL_SCRIPTS}; do
+        (
+            while true; do
+                [ -f ${SCRIPT_NAME} ] && \
+                    echo "Polling data: $(date) [${SCRIPT_NAME}]" && \
+                    php ${SCRIPT_NAME}
+                sleep ${POLL_INTERVAL}
+            done
+        ) &
+    done
 fi
 
 echo "Starting server process"