fix(scripts): Telegram job list compares SQLite vs ISO discoveredAt
This commit is contained in:
parent
ae7e50fa91
commit
8a08d4991e
@ -53,25 +53,47 @@ build_job_lines_html() {
|
|||||||
local completed="$3"
|
local completed="$3"
|
||||||
local max_n="$4"
|
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" '
|
echo "$jobs_json" | jq -c --arg s "$started" --arg e "$completed" --argjson max "$max_n" '
|
||||||
def pickurl:
|
def pickurl:
|
||||||
if (.jobUrl // "") != "" then .jobUrl
|
if (.jobUrl // "") != "" then .jobUrl
|
||||||
elif (.applicationLink // "") != "" then .applicationLink
|
elif (.applicationLink // "") != "" then .applicationLink
|
||||||
else "" end;
|
else "" end;
|
||||||
|
def normalizeTs:
|
||||||
|
if . == null or . == "" then ""
|
||||||
|
elif test("[Tt]") then .
|
||||||
|
else sub(" "; "T")
|
||||||
|
end;
|
||||||
def pickrows($all):
|
def pickrows($all):
|
||||||
($all | map(select($s != "" and $e != "" and (.discoveredAt >= $s) and (.discoveredAt <= $e)))) as $win |
|
if ($s == "" or $s == null) then
|
||||||
if ($win | length) > 0 then $win
|
{ rows: ($all | sort_by(.discoveredAt | normalizeTs) | reverse), usedFallback: true }
|
||||||
else ($all | map(select($s != "" and (.discoveredAt >= $s))))
|
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;
|
end;
|
||||||
(.data.jobs // []) as $all |
|
(.data.jobs // []) as $all |
|
||||||
if ($all | length) == 0 then
|
if ($all | length) == 0 then
|
||||||
{total: 0, lines: []}
|
{total: 0, lines: [], usedFallback: false}
|
||||||
else
|
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 | length) as $total |
|
||||||
($sorted | .[0:max]) as $slice |
|
($sorted | .[0:max]) as $slice |
|
||||||
{
|
{
|
||||||
total: $total,
|
total: $total,
|
||||||
|
usedFallback: $picked.usedFallback,
|
||||||
lines: [
|
lines: [
|
||||||
$slice[] |
|
$slice[] |
|
||||||
{
|
{
|
||||||
@ -152,15 +174,20 @@ for _ in $(seq 1 720); do
|
|||||||
sel='{"total":0,"lines":[]}'
|
sel='{"total":0,"lines":[]}'
|
||||||
total="$(echo "$sel" | jq -r '.total // 0')"
|
total="$(echo "$sel" | jq -r '.total // 0')"
|
||||||
shown="$(echo "$sel" | jq -r '.lines | length')"
|
shown="$(echo "$sel" | jq -r '.lines | length')"
|
||||||
|
used_fb="$(echo "$sel" | jq -r '.usedFallback // false')"
|
||||||
if [[ "$total" -gt 0 ]]; then
|
if [[ "$total" -gt 0 ]]; then
|
||||||
msg+=$'\n\n'"<b>Jobs in this run</b> (showing ${shown} of ${total}):"
|
if [[ "$used_fb" == "true" ]]; then
|
||||||
|
msg+=$'\n\n'"<b>Recent jobs</b> (showing ${shown} of ${total}; time window did not match — links may include older discoveries):"
|
||||||
|
else
|
||||||
|
msg+=$'\n\n'"<b>Jobs in this run</b> (showing ${shown} of ${total}):"
|
||||||
|
fi
|
||||||
append_lines_from_json "$sel" msg
|
append_lines_from_json "$sel" msg
|
||||||
rest=$((total - shown))
|
rest=$((total - shown))
|
||||||
if [[ "$rest" -gt 0 ]]; then
|
if [[ "$rest" -gt 0 ]]; then
|
||||||
msg+=$'\n\n'"<i>…and ${rest} more not shown.</i>"
|
msg+=$'\n\n'"<i>…and ${rest} more not shown.</i>"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
msg+=$'\n\n'"<i>No job rows matched this run window (time filter). Open the app for the full list.</i>"
|
msg+=$'\n\n'"<i>No job rows in the API list. Open the app for details.</i>"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
msg+=$'\n\n'"<i>Could not load GET /api/jobs for links.</i>"
|
msg+=$'\n\n'"<i>Could not load GET /api/jobs for links.</i>"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user