Cette page a été traduite par une machine et n'a pas encore été révisée par une personne. L'anglais est la référence ; les corrections sont les bienvenues sur GitHub. GitHub

Cookwala / SDK et scénarios / 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.

Audience: food safety officer · Objectif: Rendre les gens en meilleure santé, Des robots pour les gens · Niveau: beginner

Lire d'abord: /docs/CORE/ /docs/HUB/

Étapes

  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

Résultat

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

Ligne de commande

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

Sortie enregistrée

Statut: ok

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

Code

Exécuter: 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

Précédent: 050 Suivant: 052