switch to tail -f circular pipes
authorAnotherTest <ali.mpfard@gmail.com>
Fri, 10 Jan 2020 07:14:35 +0000 (10:44 +0330)
committerAnotherTest <ali.mpfard@gmail.com>
Fri, 10 Jan 2020 07:14:35 +0000 (10:44 +0330)
jq/Dockerfile
jq/run

index 31491a7..d37c7d7 100644 (file)
@@ -1,13 +1,14 @@
-FROM ubuntu:xenial
+FROM archlinux/base
 MAINTAINER Ali MohammadPur <devanothertest@gmail.com>
 
 # General test requirements
-RUN apt-get -y update
-RUN apt-get -y install python make
-RUN apt-get -y install curl
+RUN pacman -Sy
+RUN pacman -S --noconfirm python make
+RUN pacman -S --noconfirm curl
 
 RUN mkdir -p /mal
 WORKDIR /mal
 
 # test requirements
-RUN apt-get -y install jq pv coreutils
+RUN pacman -S --noconfirm jq pv coreutils
+
diff --git a/jq/run b/jq/run
index 04e5377..ad500d1 100755 (executable)
--- a/jq/run
+++ b/jq/run
@@ -5,16 +5,13 @@ XDEBUG=${DEBUG:-false}
 SELFDEBUG=${RUNDEBUG:-false}
 runjq() {
     pipe_name=$(mktemp)
-    rm -f $pipe_name $ipipe_name
-    mkfifo $pipe_name || true
+    rm -f $pipe_name
+    echo -n "" > $pipe_name
     xstdout=$(readlink /proc/self/fd/1)
     stdin=$(readlink /proc/self/fd/0)
     trap "rm -f $pipe_name" EXIT SIGINT SIGHUP
-    (
-        while [[ -e $pipe_name ]]; do
-            timeout 1 cat $pipe_name
-        done&
-    ) | jq --argjson DEBUG $XDEBUG -nrRM -f "$(dirname "$0")/${STEP:-stepA_mal}.jq" --args "${@}" |&\
+    tail -f $pipe_name 2>/dev/null |\
+    jq --argjson DEBUG $XDEBUG -nrRM -f "$(dirname "$0")/${STEP:-stepA_mal}.jq" --args "${@}" |&\
     tee \
         >(jq -Rr 'try fromjson[1]|if type == "string" then . else empty end') \
         >(jq -Rr "if $SELFDEBUG then . else empty end") \
@@ -63,4 +60,4 @@ runjq() {
 }
 my_pid=$$
 trap 'kill -INT $my_pid' EXIT SIGINT
-runjq "${@}"
\ No newline at end of file
+runjq "${@}"