(no title)
rwiggins | 7 months ago
But as an example of about where I'd stop using jq/shell scripting and switch to an actual program... we have a service that has task queues. The number of queues for an endpoint is variable, but enumerable via `GET /queues` (I'm simplifying here of course), which returns e.g. `[0, 1, 2]`. There was a bug where certain tasks would get stuck in a non-terminal state, blocking one of those queues. So, I wanted a simple little snippet to find, for each queue, (1) which task is currently executing and (2) how many tasks are enqueued. It ended up vaguely looking like:
for q in $(curl -s "$endpoint/queues" | jq -r '.[]'); do
curl -s "$endpoint/queues/$q" \
| jq --arg q "$q" '
{
"queue": $q,
"executing": .currently_executing_tasks,
"num_enqueued": (.enqueued_tasks | length)
}'
done | jq -s
which ends up producing output like (assuming queue 0 was blocked) [
{
"queue": 0,
"executing": [],
"num_enqueued": 100
},
...
]
I think this is roughly where I'd start to consider "hmm, maybe a proper script would do this better". I bet the equivalent Python is much easier to read and probably not much longer.Although, I think this example demonstrates how I typically use jq, which is like a little multitool. I don't usually write really complicated jq.
No comments yet.