You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For long-running scripts that process many nodes, it's important to support graceful abortion. This allows users to stop the script execution without leaving the repository in an inconsistent state.
428
+
429
+
```groovy
430
+
void doRun() {
431
+
repo.queryRaw("SELECT * FROM [nt:base] WHERE ISDESCENDANTNODE('/content/acme/us/en')").forEach { resource ->
432
+
// Safe point
433
+
context.checkAborted()
434
+
435
+
// Process resource
436
+
// TODO resource.save() etc.
437
+
}
438
+
}
439
+
```
440
+
441
+
Alternatively, you can use `context.isAborted()` for manual control:
442
+
443
+
```groovy
444
+
void doRun() {
445
+
def assets = repo.queryRaw("SELECT * FROM [dam:Asset] WHERE ISDESCENDANTNODE('/content/dam')").iterator()
446
+
for (asset in assets) {
447
+
if (context.isAborted()) {
448
+
// Do clean when aborted
449
+
break
450
+
}
451
+
}
452
+
// Still remember to propagate abort status
453
+
context.checkAborted()
454
+
}
455
+
```
456
+
424
457
### History
425
458
426
459
All code executions are logged in the history. You can see the status of each execution, including whether it was successful or failed. The history also provides detailed logs for each execution, including any errors that occurred.
<p>This action will abort current code execution.</p>
82
-
<p>Be aware that aborting execution may leave data in an inconsistent state.</p>
84
+
<p>
85
+
<CheckmarkCirclesize="XS"/> The abort request signals the script to stop, but the script must explicitly check for this signal by calling <code>context.checkAborted()</code>.
86
+
</p>
87
+
<p>
88
+
<CloseCirclesize="XS"/> If the script doesn't check for abort, it will continue running until it completes naturally. Only if an abort timeout is configured (by default it's not), will the execution be forcefully terminated after the timeout expires.
89
+
</p>
90
+
<p>
91
+
<AlertIconsize="XS"/> For scripts with loops or long-running operations, add <code>context.checkAborted()</code> at safe checkpoints (e.g., at the beginning of each loop iteration) to enable graceful termination and prevent data corruption.
0 commit comments