Problem
You want to react to job completions as they happen, rather than polling or blocking. This is useful for long-running batch jobs or when you need to trigger actions based on results.Solution
Use filesystem watching tools likefswatch (macOS/Linux) or inotifywait (Linux) to monitor the workspace output directory. When a job completes, trigger processing immediately.
Example
Monitor completions withfswatch:
Batch Processing with Events
Submit many jobs and collect results as they complete:Advanced Event Handling
Trigger subsequent jobs:How It Works
fswatch -0watches directories for changes (null-terminated output)read -d ''reads null-terminated paths- Pattern matching identifies completed jobs (
*/result.txt) - Actions trigger immediately when files are written
Linux Alternative
Usinginotifywait on Linux:
Use Cases
- Real-time processing: React to results immediately
- Pipeline triggers: Start next stage when previous completes
- Monitoring dashboards: Display results as they arrive
- Progress tracking: Update UI or logs in real-time
- Conditional workflows: Different actions based on result content