diff --git a/scripts/jobber-pipeline-telegram.sh b/scripts/jobber-pipeline-telegram.sh
index 6dd72f2..af04727 100755
--- a/scripts/jobber-pipeline-telegram.sh
+++ b/scripts/jobber-pipeline-telegram.sh
@@ -53,25 +53,47 @@ build_job_lines_html() {
local completed="$3"
local max_n="$4"
+ # Pipeline run times are ISO-8601 (…T…Z). Jobs often use SQLite datetime('now'): "YYYY-MM-DD HH:MM:SS".
+ # Raw string compare treats space before the clock as sorting before "T", so every SQLite-style
+ # discoveredAt incorrectly falls *before* the run window. Normalize for comparison only.
echo "$jobs_json" | jq -c --arg s "$started" --arg e "$completed" --argjson max "$max_n" '
def pickurl:
if (.jobUrl // "") != "" then .jobUrl
elif (.applicationLink // "") != "" then .applicationLink
else "" end;
+ def normalizeTs:
+ if . == null or . == "" then ""
+ elif test("[Tt]") then .
+ else sub(" "; "T")
+ end;
def pickrows($all):
- ($all | map(select($s != "" and $e != "" and (.discoveredAt >= $s) and (.discoveredAt <= $e)))) as $win |
- if ($win | length) > 0 then $win
- else ($all | map(select($s != "" and (.discoveredAt >= $s))))
+ if ($s == "" or $s == null) then
+ { rows: ($all | sort_by(.discoveredAt | normalizeTs) | reverse), usedFallback: true }
+ else
+ ($all
+ | map(select(
+ ($e != "" and ((.discoveredAt | normalizeTs) >= ($s | normalizeTs)) and ((.discoveredAt | normalizeTs) <= ($e | normalizeTs)))
+ ))) as $win |
+ if ($win | length) > 0 then { rows: $win, usedFallback: false }
+ else
+ ($all | map(select(((.discoveredAt | normalizeTs) >= ($s | normalizeTs))))) as $from |
+ if ($from | length) > 0 then { rows: $from, usedFallback: false }
+ else
+ { rows: ($all | sort_by(.discoveredAt | normalizeTs) | reverse), usedFallback: true }
+ end
+ end
end;
(.data.jobs // []) as $all |
if ($all | length) == 0 then
- {total: 0, lines: []}
+ {total: 0, lines: [], usedFallback: false}
else
- (pickrows($all) | sort_by(.discoveredAt) | reverse) as $sorted |
+ pickrows($all) as $picked |
+ ($picked.rows | sort_by(.discoveredAt | normalizeTs) | reverse) as $sorted |
($sorted | length) as $total |
($sorted | .[0:max]) as $slice |
{
total: $total,
+ usedFallback: $picked.usedFallback,
lines: [
$slice[] |
{
@@ -152,15 +174,20 @@ for _ in $(seq 1 720); do
sel='{"total":0,"lines":[]}'
total="$(echo "$sel" | jq -r '.total // 0')"
shown="$(echo "$sel" | jq -r '.lines | length')"
+ used_fb="$(echo "$sel" | jq -r '.usedFallback // false')"
if [[ "$total" -gt 0 ]]; then
- msg+=$'\n\n'"Jobs in this run (showing ${shown} of ${total}):"
+ if [[ "$used_fb" == "true" ]]; then
+ msg+=$'\n\n'"Recent jobs (showing ${shown} of ${total}; time window did not match — links may include older discoveries):"
+ else
+ msg+=$'\n\n'"Jobs in this run (showing ${shown} of ${total}):"
+ fi
append_lines_from_json "$sel" msg
rest=$((total - shown))
if [[ "$rest" -gt 0 ]]; then
msg+=$'\n\n'"…and ${rest} more not shown."
fi
else
- msg+=$'\n\n'"No job rows matched this run window (time filter). Open the app for the full list."
+ msg+=$'\n\n'"No job rows in the API list. Open the app for details."
fi
else
msg+=$'\n\n'"Could not load GET /api/jobs for links."