Schedules recurring and one-off JavaScript function calls for a repo app, and submits asynchronous background tasks for the app to process off the request thread. Registered in the app's script engine context as "scheduler", so app code calls its methods directly, e.g. scheduler.schedule(...). Each instance is scoped to a single app (by app name and data session hash) and to the current tenant organisation, resolved from CurrentRootFolderService.
Properties
| Property | Returns | Description |
|---|---|---|
| schedules | List<JsScheduleBean> | Lists every schedule registered for this app in the current tenant organisation. |
Methods
schedule(String scheduleName, String function, Integer multiple, String unit) · schedule(String scheduleName, String function, Integer multiple, String unit, String time) · schedule(String scheduleName, String function, Integer multiple, String unit, String time, Profile runAs, String funcArgs) · getSchedule(Long id) · find(String name) · getSchedules() · deleteSchedule(Long id) · clearSchedules() · getAsyncProcess(String taskName) · executeAsyncTask(String taskName, String functionName, Object params) · executeAsyncTask(String taskName, String functionName) · executeAsyncFifo(String fifoKey, String functionName, Object params) · executeAsyncFifoWithTask(String taskName, String fifoKey, String functionName, Object params) · executeAsync(String functionName, Object params)
schedule(String scheduleName, String function, Integer multiple, String unit)
Returns: JsScheduleBean
Creates a schedule that repeats at the given interval, calling function each time it fires. Equivalent to calling the four-parameter overload of schedule with no specific time of day.
| Parameter | Description |
|---|---|
scheduleName | a unique identifier provided by the calling app, eg "mySchedule" |
function | the name of the function to call when the schedule runs |
multiple | the frequency e.g. every 3 DAYS |
unit | e.g. HOURS, DAYS, WEEKS, MONTHS, ANNUAL |
schedule(String scheduleName, String function, Integer multiple, String unit, String time)
Returns: JsScheduleBean
Creates a schedule which repeats at the given interval and time of day, or a one-off if multiple and unit are null, and calls function each time it fires. Delegates to the seven-parameter overload with no runAs profile or function arguments.
| Parameter | Description |
|---|---|
scheduleName | a unique identifier provided by the calling app, eg "mySchedule" |
function | the name of the function to call when the schedule runs |
multiple | the frequency e.g. every 3 DAYS |
unit | e.g. HOURS, DAYS, WEEKS, MONTHS, ANNUAL |
time | time of day for this task to run e.g. 12:00 am |
schedule(String scheduleName, String function, Integer multiple, String unit, String time, Profile runAs, String funcArgs)
Returns: JsScheduleBean
Creates or replaces a schedule for this app, persisting its timing configuration and target function so it fires on the platform's timer regardless of whether the app is currently running. Looks up the app's AppRepository for the current tenant organisation and, when running on a website, records the current branch so the schedule fires against that website.
| Parameter | Description |
|---|---|
scheduleName | a unique identifier provided by the calling app, eg "mySchedule" |
function | the name of the function to call when the schedule runs |
multiple | the frequency e.g. every 3 DAYS |
unit | e.g. HOURS, DAYS, WEEKS, MONTHS, ANNUAL, or null for a one-off schedule |
time | time of day for this task to run e.g. 12:00 am, or null |
runAs | the profile the scheduled function should be run as, or null to run without an acting user |
funcArgs | arguments to pass through to the function when it is invoked, or null |
getSchedule(Long id)
Returns: JsScheduleBean
Looks up a single schedule for this tenant by its database id.
| Parameter | Description |
|---|---|
id | the id of the schedule |
find(String name)
Returns: JsScheduleBean
Looks up a single schedule for the current tenant organisation by the unique name it was created with.
| Parameter | Description |
|---|---|
name | the unique identifier the schedule was created with |
getSchedules()
Returns: List<JsScheduleBean>
Lists every schedule registered for this app in the current tenant organisation.
deleteSchedule(Long id)
Returns: void
Deletes a single schedule belonging to the current tenant organisation.
| Parameter | Description |
|---|---|
id | the id of the schedule to delete |
clearSchedules()
Returns: void
Deletes every schedule registered for this app in the current tenant organisation.
getAsyncProcess(String taskName)
Returns: JsProcessable
Looks up the currently tracked asynchronous task for this app with the given task name, if one is running or queued for the current tenant organisation.
| Parameter | Description |
|---|---|
taskName | the task name the process was submitted with, without the app name prefix |
executeAsyncTask(String taskName, String functionName, Object params)
Returns: JsProcessable
Queues functionName to run asynchronously, tracked under taskName so its progress can later be looked up with getAsyncProcess. Does not guarantee ordering relative to other queued tasks.
| Parameter | Description |
|---|---|
taskName | the name to track this task under, without the app name prefix |
functionName | the name of the function to call |
params | the parameters to pass to the function |
executeAsyncTask(String taskName, String functionName)
Returns: JsProcessable
Queues functionName to run asynchronously with no arguments, tracked under taskName. Equivalent to calling the varargs overload of executeAsyncTask with no params.
| Parameter | Description |
|---|---|
taskName | the name to track this task under, without the app name prefix |
functionName | the name of the function to call |
executeAsyncFifo(String fifoKey, String functionName, Object params)
Returns: JsProcessable
Queues functionName to run asynchronously, guaranteeing that tasks sharing the same fifoKey are processed in the order they were submitted. Equivalent to calling executeAsyncFifoWithTask with no task name.
| Parameter | Description |
|---|---|
fifoKey | a key shared by tasks that must be processed in submission order |
functionName | the name of the function to call |
params | the parameters to pass to the function |
executeAsyncFifoWithTask(String taskName, String fifoKey, String functionName, Object params)
Returns: JsProcessable
Queues functionName to run asynchronously, guaranteeing that tasks sharing the same fifoKey are processed in the order they were submitted, and tracking the task under taskName so its progress can later be looked up with getAsyncProcess.
| Parameter | Description |
|---|---|
taskName | the name to track this task under, without the app name prefix, or null to skip tracking |
fifoKey | a key shared by tasks that must be processed in submission order |
functionName | the name of the function to call |
params | the parameters to pass to the function |
executeAsync(String functionName, Object params)
Returns: JsProcessable
Queues functionName to run asynchronously, untracked and with no ordering guarantee relative to other queued tasks.
| Parameter | Description |
|---|---|
functionName | the name of the function to call |
params | the parameters to pass to the function |