diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-08-02 21:16:34 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-08-02 21:16:34 +0800 |
| commit | e6bcc2276b8c06190229159ff990b1a0dd2b267d (patch) | |
| tree | 53d9419a00c96b67356b106dfc3cf0a306fd4eb2 /pub.sh | |
| parent | 1035560298d8e5ff0cd0ccde433aed624c546604 (diff) | |
| download | lex-e6bcc2276b8c06190229159ff990b1a0dd2b267d.tar.gz | |
Rename to pub/sub.
Diffstat (limited to 'pub.sh')
| -rw-r--r-- | pub.sh | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ +#!/bin/sh + +FIFO_PATH="${QUEUE_PATH:-/tmp/job_queue.txt}" + +# Validate argument +if [ $# -eq 0 ] || [ -z "$1" ]; then + echo "Usage: $0 \"message to publish\"" >&2 + exit 1 +fi + +MESSAGE="$1" + +# Ensure the FIFO exists (create if missing) +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 + # Format and cap log line at 72 chars + log_line="[$(date '+%H:%M:%S')] Published: ${MESSAGE}" + if [ ${#log_line} -gt 72 ]; then + printf "[%s] Published: %.45s...\n" "$(date '+%H:%M:%S')" "$MESSAGE" + else + echo "$log_line" + fi +else + echo "[$(date '+%H:%M:%S')] ERROR: Failed to write to FIFO at $FIFO_PATH" >&2 + exit 1 +fi |
