From 1035560298d8e5ff0cd0ccde433aed624c546604 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sun, 2 Aug 2026 20:45:59 +0800 Subject: Change Unix fifo to a spool file. --- producer.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'producer.sh') diff --git a/producer.sh b/producer.sh index e05dca4..4e9ec41 100644 --- a/producer.sh +++ b/producer.sh @@ -1,6 +1,6 @@ #!/bin/sh -FIFO_PATH="${QUEUE_FIFO_PATH:-/tmp/job_queue}" +FIFO_PATH="${QUEUE_PATH:-/tmp/job_queue.txt}" # Validate argument if [ $# -eq 0 ] || [ -z "$1" ]; then @@ -11,18 +11,13 @@ fi MESSAGE="$1" # Ensure the FIFO exists (create if missing) -if [ ! -p "$FIFO_PATH" ]; then - mkfifo -m 0600 "$FIFO_PATH" || { - echo "[$(date '+%H:%M:%S')] ERROR: Failed to create FIFO at $FIFO_PATH" >&2 - exit 1 - } -fi - -# Handle SIGPIPE gracefully so the producer doesn't crash if the consumer disconnects -trap '' PIPE +touch "$FIFO_PATH" 2>/dev/null || { + echo "[$(date '+%H:%M:%S')] ERROR: Failed to access queue file at $FIFO_PATH" >&2 + exit 1 +} # Publish message to the FIFO -if echo "$MESSAGE" > "$FIFO_PATH" 2>/dev/null; then +if echo "$MESSAGE" >> "$FIFO_PATH" 2>/dev/null; then # Format and cap log line at 72 chars log_line="[$(date '+%H:%M:%S')] Published: ${MESSAGE}" if [ ${#log_line} -gt 72 ]; then -- cgit v1.2.3