A queue snapshot script can count fixed status buckets and show the bucket requested by a selector.

Program

Play the script to choose the status bucket and inspect the queue snapshot report.

wanted_status
queue_snapshot_report.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash

wanted_status="open"
open_count=0
waiting_count=0
tickets="open:high waiting:normal open:normal"
for ticket in $tickets; do
    status="${ticket%%:*}"
    if [[ "$status" == "open" ]]; then
        open_count=$((open_count + 1))
    else
        waiting_count=$((waiting_count + 1))
    fi
done
if [[ "$wanted_status" == "open" ]]; then
    shown=$open_count
else
    shown=$waiting_count
fi
echo "$wanted_status tickets=$shown open=$open_count waiting=$waiting_count"
#!/usr/bin/env bash

wanted_status="waiting"
open_count=0
waiting_count=0
tickets="open:high waiting:normal open:normal"
for ticket in $tickets; do
    status="${ticket%%:*}"
    if [[ "$status" == "open" ]]; then
        open_count=$((open_count + 1))
    else
        waiting_count=$((waiting_count + 1))
    fi
done
if [[ "$wanted_status" == "open" ]]; then
    shown=$open_count
else
    shown=$waiting_count
fi
echo "$wanted_status tickets=$shown open=$open_count waiting=$waiting_count"
  1. wanted_status ← open

    3wanted_status="open"4open_count=0
    values this stepopenwanted_status
  2. open_count ← 0

    3wanted_status="open"4open_count=05waiting_count=0
    values this step0open_count
  3. waiting_count ← 0

    4open_count=05waiting_count=06tickets="open:high waiting:normal open:normal"
    values this step0waiting_count
  4. tickets ← open:high waiting:normal open:normal

    5waiting_count=06tickets="open:high waiting:normal open:normal"7for ticket in $tickets; do
    values this stepopen:high waiting:normal open:normaltickets
  5. status ← open

    7for ticket in $tickets; do8    status="${ticket%%:*}"9    if [[ "$status" == "open" ]]; then
    values this stepopenstatusopen:highticket
  6. open_count ← 1

    9if [[ "$status" == "open" ]]; then10    open_count=$((open_count + 1))11else
    values this step0 1open_count
  7. status ← waiting

    7for ticket in $tickets; do8    status="${ticket%%:*}"9    if [[ "$status" == "open" ]]; then
    values this stepwaitingstatuswaiting:normalticket
  8. waiting_count ← 1

    11else12    waiting_count=$((waiting_count + 1))13fi
    values this step0 1waiting_count
  9. status ← open

    7for ticket in $tickets; do8    status="${ticket%%:*}"9    if [[ "$status" == "open" ]]; then
    values this stepopenstatusopen:normalticket
  10. open_count ← 2

    9if [[ "$status" == "open" ]]; then10    open_count=$((open_count + 1))11else
    values this step1 2open_count
  11. if [[ "$wanted_status" == "open" ]]; then

    14done15if [[ "$wanted_status" == "open" ]]; then16    shown=$open_count
    values this stepopenwanted_status
  12. shown ← 2

    15if [[ "$wanted_status" == "open" ]]; then16    shown=$open_count17else
    values this step2shown2open_count
  13. echo "$wanted_status tickets=$shown open=$open_count waiting=$waiting_…

    19fi20echo "$wanted_status tickets=$shown open=$open_count waiting=$waiting_count"
    outputopen tickets=2 open=2 waiting=1
    values this stepopenwanted_status2shown2open_count1waiting_count
  1. wanted_status ← waiting

    3wanted_status="waiting"4open_count=0
    values this stepwaitingwanted_status
  2. open_count ← 0

    3wanted_status="waiting"4open_count=05waiting_count=0
    values this step0open_count
  3. waiting_count ← 0

    4open_count=05waiting_count=06tickets="open:high waiting:normal open:normal"
    values this step0waiting_count
  4. tickets ← open:high waiting:normal open:normal

    5waiting_count=06tickets="open:high waiting:normal open:normal"7for ticket in $tickets; do
    values this stepopen:high waiting:normal open:normaltickets
  5. status ← open

    7for ticket in $tickets; do8    status="${ticket%%:*}"9    if [[ "$status" == "open" ]]; then
    values this stepopenstatusopen:highticket
  6. open_count ← 1

    9if [[ "$status" == "open" ]]; then10    open_count=$((open_count + 1))11else
    values this step0 1open_count
  7. status ← waiting

    7for ticket in $tickets; do8    status="${ticket%%:*}"9    if [[ "$status" == "open" ]]; then
    values this stepwaitingstatuswaiting:normalticket
  8. waiting_count ← 1

    11else12    waiting_count=$((waiting_count + 1))13fi
    values this step0 1waiting_count
  9. status ← open

    7for ticket in $tickets; do8    status="${ticket%%:*}"9    if [[ "$status" == "open" ]]; then
    values this stepopenstatusopen:normalticket
  10. open_count ← 2

    9if [[ "$status" == "open" ]]; then10    open_count=$((open_count + 1))11else
    values this step1 2open_count
  11. if [[ "$wanted_status" == "open" ]]; then

    14done15if [[ "$wanted_status" == "open" ]]; then16    shown=$open_count
    values this stepwaitingwanted_status
  12. shown ← 1

    17else18    shown=$waiting_count19fi
    values this step1shown1waiting_count
  13. echo "$wanted_status tickets=$shown open=$open_count waiting=$waiting_…

    19fi20echo "$wanted_status tickets=$shown open=$open_count waiting=$waiting_count"
    outputwaiting tickets=1 open=2 waiting=1
    values this stepwaitingwanted_status1shown2open_count1waiting_count
bucket counters Each status bucket is a scalar counter that stays easy to inspect.
status selector The selector changes which bucket is highlighted without changing the source shape.
snapshot output The report includes the selected bucket and the full queue summary.