WATCH
Register event-driven triggers that fire an OQL block when a condition changes. WATCH is poll-based for external sources (weather, currency) and inotify-based for filesystem changes.
| Source | Syntax |
|---|---|
| Filesystem | WATCH "fs:/root/uploads/" ON "create" OPEN NEST ... CLOSE NEST |
| Weather change | WATCH "weather:Cape Town" ON "change" OPEN NEST ... CLOSE NEST |
| Currency change | WATCH "currency:USD/ZAR" ON "change" OPEN NEST ... CLOSE NEST |
| Stream event | WATCH "stream:channel_name" ON "message" OPEN NEST ... CLOSE NEST |
Watch for file uploads
WATCH "fs:/root/uploads/" ON "create"
OPEN NEST
EMIT "New file: " & !EVENT(path)
AFTER OCR !EVENT(path) SET ?text
AFTER INSERT ?text_record INTO "documents" FROM "app"
CLOSE NEST
Watch for currency movement
WATCH "currency:USD/ZAR" ON "change"
OPEN NEST
EMAIL "USD/ZAR changed to " & !EVENT(value) TO "trader@example.com" WITH "FX Alert"
CLOSE NEST
Event object fields
| Source | !EVENT fields |
|---|---|
| Filesystem | path, event (create|modify|delete) |
| Weather / Currency | type ("change"), value (new), prev (old) |
| Stream | channel, message (the streamed value) |
Manage watches
LIST WATCHES SET ?watches
AFTER EMIT ?watches
DELETE WATCH "currency:USD/ZAR"