Cron samples
Cron expression format
The expression field follows a 6-field cron format:
? ? ? ? ? ? ? ? ? ? ? ??? day of week (MON, TUE, WED, THU, FRI, SAT, SUN) ? ? ? ? ????? month (1 - 12) ? ? ? ??????? day of month (1 - 31) ? ? ????????? hour (0 - 23) ? ??????????? min (0 - 59) ????????????? seconds (0 - 59)
| Field | Values |
|---|---|
|
seconds |
0–59 |
|
minute |
0–59 |
|
hour |
0–23 |
|
day of month |
1–31 |
|
month |
1–12 |
|
day of week |
MON, TUE, WED, THU, FRI, SAT, SUN |
Expression samples:
"0 0 * * * *"= every hour of every day."*/10 * * * * *"= every ten seconds."0 0 8-10 * * *"= 8, 9 and 10 o'clock of every day."0 0 6,19 * * *"= 6:00 AM and 7:00 PM every day."0 0/30 8-10 * * *"= 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day."0 0 9-17 * * MON-FRI"= on the hour during nine-to-five weekdays."0 0 0 25 12 ?"= every Christmas Day at midnight
Methods
findAll
Description:
| Method | Return values | Description |
|---|---|---|
|
findAll() |
List<CronTab> |
Returns a list of all crontabs. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.CronTab;
import com.openkm.sdk4j.impl.OKMWebservices;
import java.util.List;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
List<CronTab> cronTabs = ws.cronTab.findAll();
for (CronTab ct : cronTabs) {
System.out.println(ct);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
update
Description:
| Method | Return values | Description |
|---|---|---|
|
update(long id, String name, String expression, Boolean active) |
void |
Update a crontab. |
|
Parameter description:
|
||
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
long cronTabId = 1; // A valid crontab id
ws.cronTab.update(cronTabId, "My task", "0 0 8-10 * * *", true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
reset
Description:
| Method | Return values | Description |
|---|---|---|
|
reset(long id) |
void |
Reset error and set end time for a crontab. |
|
This method clears the error state of a crontab and updates its last end time. Use it to recover a crontab after a failed execution. |
||
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
long cronTabId = 1; // A valid crontab id
ws.cronTab.reset(cronTabId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
execute
Description:
| Method | Return values | Description |
|---|---|---|
|
execute(long id) |
void |
Execute a crontab task manually. |
|
Triggers the crontab task immediately, regardless of its scheduled expression. |
||
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
long cronTabId = 1; // A valid crontab id
ws.cronTab.execute(cronTabId);
} catch (Exception e) {
e.printStackTrace();
}
}
}