...not that clean. Custom functions can only use a handful of Apps Script services (no ScriptApp, no triggers, that nevertheless tend to be coarse). I can’t think of a way to measure execution without polling, let alone fail gracefully. A crazy idea, though...