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
Copy file name to clipboardExpand all lines: README.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,7 @@ It works seamlessly across AEM on-premise, AMS, and AEMaaCS environments.
59
59
-[Console](#console)
60
60
-[Content scripts](#content-scripts)
61
61
-[Minimal example](#minimal-example)
62
+
-[Conditions](#conditions)
62
63
-[Inputs example](#inputs-example)
63
64
-[Outputs example](#outputs-example)
64
65
-[Console \& logging](#console--logging)
@@ -303,6 +304,43 @@ The `doRun()` method contains the actual code to be executed.
303
304
Notice that the script on their own decide when to run without a need to specify any additional metadata. In that way the-sky-is-the-limit. You can run the script once, periodically, or at an exact date and time.
304
305
There are many built-in, ready-to-use conditions available in the `conditions`[service](https://github.com/wttech/acm/blob/main/core/src/main/java/dev/vml/es/acm/core/code/Conditions.java).
305
306
307
+
#### Conditions
308
+
309
+
Conditions determine when automatic scripts should execute. The `conditions`[service](https://github.com/wttech/acm/blob/main/core/src/main/java/dev/vml/es/acm/core/code/Conditions.java) provides many useful methods:
310
+
311
+
-`conditions.always()` - Always execute on every trigger. Most commonly used in console and manual scripts where execution is triggered directly by users.
312
+
-`conditions.never()` - Never execute. Useful for temporarily disabling scripts.
313
+
-`conditions.changed()` - Execute when script content changed or when instance changed after a failure. Automatically retries failed executions after deployments, making it more suitable for production scenarios than `once()`.
314
+
-`conditions.contentChanged()` - Execute when script content changed or when never executed before. Does not consider instance state changes.
315
+
-`conditions.instanceChanged()` - Execute when instance state changed (OSGi bundle checksums changed or ACM bundle restarted). Useful for detecting deployments or restarts.
316
+
-`conditions.retryIfInstanceChanged()` - Execute when instance state changed and previous execution failed. Combines instance change detection with failure retry logic.
317
+
-`conditions.once()` - Execute only once, when never executed before. Does not automatically retry after failures. Works well for initialization scripts that should not be repeated.
318
+
-`conditions.notSucceeded()` - Execute if previous execution wasn't successful. Retries execution until it succeeds, ignoring script content and instance state changes.
319
+
-`conditions.isInstanceAuthor()` / `conditions.isInstancePublish()` - Execute only on specific instance types (author or publish).
320
+
-`conditions.isInstanceRunMode("dev")` - Execute only when instance has specific run mode.
321
+
-`conditions.isInstanceOnPrem()` - Execute only on on-premise AEM instances.
322
+
-`conditions.isInstanceCloud()` - Execute only on cloud-based AEM instances (AEMaaCS).
323
+
-`conditions.isInstanceCloudSdk()` - Execute only on AEM Cloud SDK (local development environment).
324
+
-`conditions.isInstanceCloudContainer()` - Execute only on AEM Cloud Service containers (non-SDK cloud instances).
325
+
326
+
**Example usage:**
327
+
328
+
```groovy
329
+
boolean canRun() {
330
+
return conditions.once()
331
+
}
332
+
333
+
void doRun() {
334
+
out.info "Removing deprecated properties from pages..."
For the complete list of available conditions and their behavior, see the [Conditions.java source code](https://github.com/wttech/acm/blob/main/core/src/main/java/dev/vml/es/acm/core/code/Conditions.java).
343
+
306
344
#### Inputs example
307
345
308
346
Scripts could accept inputs, which are passed to the script when it is executed.
Copy file name to clipboardExpand all lines: ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/automatic/example/ACME-100_acl.groovy
+25-6Lines changed: 25 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,21 @@
1
-
/**
2
-
* This script creates content author groups for each tenant-country-language combination.
3
-
*
4
-
* The groups are named in the format: `{tenant}-{country}-{language}-content-authors`.
5
-
* Each group is granted read, write, and replicate permissions on the corresponding content and DAM paths.
6
-
*/
1
+
/*
2
+
---
3
+
tags: ['security', 'acl']
4
+
schedule: Every hour at 10 minutes past the hour
5
+
---
6
+
Creates content author groups for each tenant-country-language combination.
7
+
8
+
The groups are named in the format: `{tenant}-{country}-{language}-content-authors`.
9
+
Each group is granted read, write, and replicate permissions on the corresponding content and DAM paths.
10
+
11
+
```mermaid
12
+
graph LR
13
+
A[Scan Tenants] --> B[Find Countries]
14
+
B --> C[Find Languages]
15
+
C --> D[Create Author Groups]
16
+
D --> E[Grant Permissions]
17
+
```
18
+
*/
7
19
8
20
defscheduleRun() {
9
21
return schedules.cron("0 10 * ? * * *") // every hour at minute 10
Copy file name to clipboardExpand all lines: ui.content.example/src/main/content/jcr_root/conf/acm/settings/script/automatic/example/ACME-32_every-day.groovy
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,10 @@
1
+
/*
2
+
A scheduled script that runs daily at 08:00.
3
+
4
+
This script demonstrates cron-based scheduling with `schedules.cron()` and uses
5
+
`conditions.always()` to execute on every scheduled trigger.
6
+
*/
7
+
1
8
defscheduleRun() {
2
9
return schedules.cron("0 0 8 ? * * *") // at 08:00 every day
0 commit comments