Esta página fue traducida por una máquina y aún no ha sido revisada por una persona. El inglés es la referencia; las correcciones son bienvenidas en GitHub. GitHub

Cookwala / SDK y escenarios / 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.

Audiencia: food safety officer · Objetivo: Hacer que las personas estén más sanas, Robots para las personas · Nivel: beginner

Leer primero: /docs/CORE/ /docs/HUB/

Pasos

  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.

Línea de comandos

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

Salida grabada

Estado: ok

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

Código

Ejecutar: 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 Siguiente: 052