Esta página foi traduzida por máquina e ainda não foi revisada por uma pessoa. O inglês é a referência; correções são bem-vindas no GitHub. GitHub

Cookwala / SDK e cenários / 051

Report an anonymous incident to a catalog

Incident reports carry a date, a category, a severity, the operation and the safety limits that fired, and no names or ids, so every maker learns from each near miss. Send the example report and read the recall list it feeds.

Público: food safety officer · Objetivo: Torne as pessoas mais saudáveis, Robôs para pessoas · Nível: beginner

Leia primeiro: /docs/CORE/ /docs/HUB/

Passos

  1. Submit the example report: oil reached 201 °C while a robot waited for a delivery; the oil.max_temp limit cut the heat. The catalog answers received. reportIncident

  2. Recalls are the catalog's other door: what it publishes after reviewing incidents. The reference hub publishes none. recalls

Resultado

You have filed an incident that names no one. Next: scenario 052 reads a signed recall.

Linha de comando

cookwala hub --recipes examples --speed 200
curl -s -X POST http://localhost:7878/v1/incidents -H 'Content-Type: application/json' -H 'Idempotency-Key: inc-2026-0001' -d @examples/core/incident.json
curl -s http://localhost:7878/v1/recalls

Saída gravada

Status: ok

[1] reportIncident: {"received": true}
[2] recalls: []

Código

Executar: python scenarios/out/051-report-an-incident/python.py

# Scenario 051: Report an anonymous incident to a catalog
# Incident reports carry a date, a category, a severity, the operation and the safety limits that fired, and no names or ids, so every maker learns from each near miss. Send the example report and read the recall list it feeds.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem

def load(path):
    with open(path, encoding="utf-8") as f:
        return json.load(f)

def pick(obj, path):
    for part in path.replace("]", "").replace("[", ".").split("."):
        obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
    return obj

c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))


# Step 1: Submit the example report: oil reached 201 °C while a robot waited for a delivery; the oil.max_temp limit cut the heat. The catalog answers received.
r = c.report_incident(load("examples/core/incident.json"))
assert pick(r, "received") == True, pick(r, "received")
print("ok", "received", "=", True)

# Step 2: Recalls are the catalog's other door: what it publishes after reviewing incidents. The reference hub publishes none.
recalls = c.recalls()
assert pick(recalls, "length") == 0, pick(recalls, "length")
print("ok", "length", "=", 0)

print("scenario complete")

scenarios/051-report-an-incident.json

Anterior: 050 Próximo: 052