chore: gitignore cron Telegram env; ship pipeline+Telegram script and deploy steps

Made-with: Cursor
This commit is contained in:
2026-04-04 16:10:27 -04:00
parent 8d8c6f0ed0
commit 14b7bb34cf
4 changed files with 240 additions and 46 deletions
+11
View File
@@ -0,0 +1,11 @@
# Copy to /root/.jobber-cron.env and chmod 600. Do not commit real values.
#
# TELEGRAM_CHAT_ID: from getUpdates → result[0].message.chat.id
# Private DMs: usually the same as your Telegram user id.
TELEGRAM_BOT_TOKEN=""
TELEGRAM_CHAT_ID=""
JOBOPS_URL="http://127.0.0.1:3005"
# Optional — only if BASIC_AUTH_USER / BASIC_AUTH_PASSWORD are set in Jobber .env
# BASIC_AUTH_USER=""
# BASIC_AUTH_PASSWORD=""
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# Run Jobber pipeline, wait until it finishes, send summary to Telegram.
# Secrets: copy scripts/jobber-cron.env.example to /root/.jobber-cron.env (chmod 600).
set -euo pipefail
ENV_FILE="${JOBBER_CRON_ENV:-/root/.jobber-cron.env}"
if [[ ! -f "$ENV_FILE" ]]; then
echo "Missing env file: $ENV_FILE (set JOBBER_CRON_ENV or create the default path)" >&2
exit 1
fi
# shellcheck source=/dev/null
source "$ENV_FILE"
: "${TELEGRAM_BOT_TOKEN:?Set TELEGRAM_BOT_TOKEN in $ENV_FILE}"
: "${TELEGRAM_CHAT_ID:?Set TELEGRAM_CHAT_ID in $ENV_FILE}"
BASE="${JOBOPS_URL:-http://127.0.0.1:3005}"
AUTH=()
if [[ -n "${BASIC_AUTH_USER:-}" && -n "${BASIC_AUTH_PASSWORD:-}" ]]; then
AUTH=(-u "${BASIC_AUTH_USER}:${BASIC_AUTH_PASSWORD}")
fi
send_tg() {
local msg="$1"
curl -sS -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg c "$TELEGRAM_CHAT_ID" --arg t "$msg" '{chat_id: $c, text: $t}')" >/dev/null
}
fetch_status() {
curl -sS "${AUTH[@]}" "${BASE}/api/pipeline/status"
}
body="$(fetch_status)"
if ! echo "$body" | jq -e '.ok == true' >/dev/null 2>&1; then
send_tg "Jobber: /api/pipeline/status failed (before run). Check container."
exit 1
fi
if echo "$body" | jq -e '.data.isRunning == true' >/dev/null 2>&1; then
send_tg "Jobber: pipeline already running; skipping scheduled run."
exit 0
fi
resp="$(curl -sS "${AUTH[@]}" -X POST "${BASE}/api/pipeline/run" \
-H "Content-Type: application/json" -d '{}')"
if ! echo "$resp" | jq -e '.ok == true' >/dev/null 2>&1; then
send_tg "Jobber: POST /api/pipeline/run failed: $(echo "$resp" | jq -c .)"
exit 1
fi
was_running=0
for _ in $(seq 1 720); do
sleep 30
body="$(fetch_status)"
if ! echo "$body" | jq -e '.ok == true' >/dev/null 2>&1; then
send_tg "Jobber: status check failed mid-run."
exit 1
fi
running="$(echo "$body" | jq -r '.data.isRunning')"
if [[ "$running" == "true" ]]; then
was_running=1
elif [[ "$was_running" -eq 1 ]]; then
lr="$(echo "$body" | jq '.data.lastRun')"
st="$(echo "$lr" | jq -r '.status // "unknown"')"
disc="$(echo "$lr" | jq -r '.jobsDiscovered // 0')"
proc="$(echo "$lr" | jq -r '.jobsProcessed // 0')"
err="$(echo "$lr" | jq -r '.errorMessage // empty')"
msg="Jobber pipeline finished: ${st}. Discovered: ${disc}, processed: ${proc}."
[[ -n "$err" ]] && msg="${msg}"$'\n'"Error: ${err}"
send_tg "$msg"
exit 0
fi
done
send_tg "Jobber: timed out waiting for pipeline (6h). Check server."
exit 1