Queues: ten tasks and go to sleep|INEMA.CLUB-PRO

Lesson 3 · 20 min

A Homegrown Queue in 30 Lines

Before the bot, you’ll see the whole idea in a short script from the jornada-agentes repository: four folders, one task at a time, resume after Ctrl+C, and failures kept separate with the reason.

Start lesson
Notebook with a dark terminal beside four paper folders on a desk.

In this lesson, you’ll

  1. 1The four folders and a task’s path
  2. 2Resuming, in practice
  3. 3The script, line by line
  4. 4Switch the engine: claude or codex

Goal: run the homegrown queue, interrupt it halfway through, and explain why the second run doesn’t redo what’s already done.

01A file’s path

Each request is a .md file that moves between folders.

Scroll down: each step below lights up its part of the diagram.

  1. 1/5

    entrada/

    Each .md file is a request, written the way you’d write it in chat. The order follows the file names.

  2. 2/5

    rodando/

    The script moves the file here before calling the agent. If you press Ctrl+C or the computer crashes, it stays here, which makes it possible to resume.

  3. 3/5

    feito/

    It worked (exit code 0 and a non-empty response): the final file contains the request, a line with ---, and the agent’s response.

  4. 4/5

    falhou/

    It failed or the response was empty: the file goes here with the exit code and what the agent printed. The queue moves on to the next task.

  5. 5/5

    Running it again only picks up what’s left

    At startup, the script returns anything left in rodando/ to entrada/. Anything already in feito/ is never redone.

Click each folder. The key is rodando/: the task only leaves that folder when it finishes, moving to feito/ or falhou/.

02See the queue in action

Run it, interrupt it halfway through with the Ctrl+C button, then run it again.

entrada/

rodando/

feito/

falhou/

Illustrative browser simulation: the tasks don’t actually run. The failure is intentional, to show the falhou/ folder.

03The script and how to use it

It’s in ferramentas/fila-caseira.sh in the jornada-agentes repository. Both engines run through your subscription.

Terminal · set up and run
git clone https://github.com/inematds/jornada-agentes.git
cd jornada-agentes
mkdir -p fila/entrada
echo "Summarize in 5 lines what a task queue is." > fila/entrada/01.md
echo "List 3 risks of leaving an agent running on its own." > fila/entrada/02.md
./ferramentas/fila-caseira.sh fila          # default engine: claude
./ferramentas/fila-caseira.sh fila codex    # or codex
Inside fila-caseira.sh (shortened for reading)
mkdir -p "$PASTA/entrada" "$PASTA/rodando" "$PASTA/feito" "$PASTA/falhou"

# resume: anything left in "rodando" (crash, Ctrl+C) goes back to the queue
for f in "$PASTA"/rodando/*.md; do [ -e "$f" ] && mv "$f" "$PASTA/entrada/"; done

for f in "$PASTA"/entrada/*.md; do
  [ -e "$f" ] || { echo "empty queue"; break; }
  nome=$(basename "$f")
  mv "$f" "$PASTA/rodando/$nome"          # picks up the task (only one at a time)
  saida=$(claude -p "$(cat "$PASTA/rodando/$nome")" < /dev/null 2>&1); rc=$?
  if [ $rc -eq 0 ] && [ -n "$saida" ]; then
    # request + --- + response go to feito/
  else
    # request + ERROR (rc) + output go to falhou/
  fi
done
Repository example
→ 01.md
  feito
→ 02.md
  feito
entrada: 0 · feito: 2 · falhou: 0

04Practice

Use two tasks from your queue on paper (lesson 2).

E2 · A homemade queue in 30 lines

30 min

Create two or three tasks in fila/entrada and run fila-caseira.sh. In a second run, interrupt with Ctrl+C while a task is in rodando/, check the folder, and run it again.

Done when: the tasks are in fila/feito with their responses, and you saw the queue continue where it left off after Ctrl+C.

Script: jornada-agentes/ferramentas/fila-caseira.sh.

05Test what you learned

The explanation appears after your answer.

Question 1 of 3

You interrupted the queue in the middle of a task. What happens when you run it again?skill

To learn more

Previous lessonNext lesson