Added response topic and changed the topic back so that I can talk on different channels
This commit is contained in:
@@ -49,30 +49,48 @@ fi
|
|||||||
# 2. Read the payload safely
|
# 2. Read the payload safely
|
||||||
PAYLOAD=$(cat "$eventfile")
|
PAYLOAD=$(cat "$eventfile")
|
||||||
|
|
||||||
# 3. Wait for connection to rclone endpoint
|
# Step 3: Connection Check
|
||||||
connect_success=0
|
|
||||||
for i in $(seq 5); do
|
for i in $(seq 5); do
|
||||||
log "INFO" "Waiting on rclone endpoint... $i"
|
log "INFO" "Waiting on rclone endpoint... $i"
|
||||||
[ "$(nc -z "$RCLONE_ENDPOINT" "$RCLONE_PORT")" ] || connect_success=1
|
if nc -z "$RCLONE_ENDPOINT" "$RCLONE_PORT"; then
|
||||||
[ "$connect_success" ] && break
|
connect_success=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$connect_success" ] || ( log "ERROR" "Remote repository not accessable" && exit 1 )
|
# Step 4: Publish
|
||||||
|
# Added -m flag and removed the [ "$( ... )" ] wrapper
|
||||||
# 4. Publish and log success/failure
|
if mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" -m "$PAYLOAD"; then
|
||||||
if [ "$(mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "$PAYLOAD")" ]; then
|
log "INFO" "Successfully published event."
|
||||||
|
else
|
||||||
log "ERROR" "Failed to connect to mosquitto broker."
|
log "ERROR" "Failed to connect to mosquitto broker."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
|
||||||
log "INFO" "Successfully published event."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 5. Wait for response from daemon
|
# 5. Wait for response from daemon
|
||||||
mosquitto_sub -h 127.0.0.1 -p 1883 -q 0 -t "$TOPIC" | while IFS="=" read -r key value
|
log "INFO" "Waiting for sync confirmation on $RESPONSE_TOPIC..."
|
||||||
|
|
||||||
|
# Start a subshell that kills the subscriber after 10 seconds if no message arrives
|
||||||
|
( sleep 10; mosquitto_pub -h 127.0.0.1 -t "$RESPONSE_TOPIC" -m "SaveSync=timeout" ) &
|
||||||
|
TIMEOUT_PID=$!
|
||||||
|
|
||||||
|
# -C 1 ensures we exit after receiving either the real response or the timeout message
|
||||||
|
mosquitto_sub -h 127.0.0.1 -p 1883 -t "$RESPONSE_TOPIC" -C 1 | while IFS="=" read -r key value
|
||||||
do
|
do
|
||||||
|
# Kill the background sleep timer since we got a message
|
||||||
|
kill "$TIMEOUT_PID" 2>/dev/null
|
||||||
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
"SaveSync") call_exit "$value";;
|
"SaveSync")
|
||||||
|
if [ "$value" = "timeout" ]; then
|
||||||
|
log "ERROR" "Sync timed out! Daemon might be down."
|
||||||
|
call_exit 1
|
||||||
|
else
|
||||||
|
log "INFO" "Sync confirmed with status: $value"
|
||||||
|
call_exit "$value"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ export LOG_FILE="/recalbox/share/system/logs/savesync_monitor.log"
|
|||||||
export ERROR_FILE="/recalbox/share/system/logs/savesync_error.log"
|
export ERROR_FILE="/recalbox/share/system/logs/savesync_error.log"
|
||||||
export DEBUG_MODE=1
|
export DEBUG_MODE=1
|
||||||
export REMOTE_BASE="saves:gamepi-tv"
|
export REMOTE_BASE="saves:gamepi-tv"
|
||||||
export TOPIC="/Recalbox/EmulationStation/Event"
|
export TOPIC="/Recalbox/SaveSync/Event"
|
||||||
export LOG_TOPIC="/Recalbox/Log/Service"
|
export LOG_TOPIC="/Recalbox/SaveSync/Service"
|
||||||
|
export RESPONSE_TOPIC="/Recalbox/SaveSync/Response"
|
||||||
|
|||||||
Reference in New Issue
Block a user