script.complete
Stops the process immediately and marks the run as succeeded, showing the given reason.
js
script.complete(reason)Parameters
| Parameter | Type | Description |
|---|---|---|
reason | string | Why the process finished early. This is shown to the user and written to the process log. |
How it stops the process
script.complete is a hard stop, the successful counterpart of script.fail. The moment it is called:
- The rest of the current function (
pre,begin,dataorend) does not run. - No further
data(record)rows are processed. end()does not run.- Any rows still queued in a batch are not flushed. Flush the batch yourself before calling
script.completeif those rows need to be written.
The run is reported as finished, not aborted, with reason as the message. Use it to bail out cleanly when there is nothing to do, so a scheduled run with no work doesn't show up as a failure.
Don't catch it
script.complete works by throwing. If it is called inside a try block whose catch swallows the error, the process will not stop. Call it outside the try, or rethrow from the catch.
Examples
Finish early when there is nothing to load
js
function begin() {
const files = datasource.files("uploads/actuals");
if (files.length === 0) {
script.complete("No new files in uploads/actuals.");
}
// Only runs when there is something to load
script.log("Loading " + files.length + " file(s)");
}Skip a run outside the business window
js
function pre() {
const day = new Date().getDay(); // 0 = Sunday, 6 = Saturday
if (day === 0 || day === 6) {
script.complete("Weekend run skipped.");
}
}Related
- script.fail: stop immediately and mark the run as failed.
- script.abort: record a failure but let the current function finish.
- process.skip: skip one record in
data()and carry on with the next.