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

PropertyReturnsDescription
schedulesList<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.

ParameterDescription
scheduleNamea unique identifier provided by the calling app, eg "mySchedule"
functionthe name of the function to call when the schedule runs
multiplethe frequency e.g. every 3 DAYS
unite.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.

ParameterDescription
scheduleNamea unique identifier provided by the calling app, eg "mySchedule"
functionthe name of the function to call when the schedule runs
multiplethe frequency e.g. every 3 DAYS
unite.g. HOURS, DAYS, WEEKS, MONTHS, ANNUAL
timetime 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.

ParameterDescription
scheduleNamea unique identifier provided by the calling app, eg "mySchedule"
functionthe name of the function to call when the schedule runs
multiplethe frequency e.g. every 3 DAYS
unite.g. HOURS, DAYS, WEEKS, MONTHS, ANNUAL, or null for a one-off schedule
timetime of day for this task to run e.g. 12:00 am, or null
runAsthe profile the scheduled function should be run as, or null to run without an acting user
funcArgsarguments 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.

ParameterDescription
idthe 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.

ParameterDescription
namethe 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.

ParameterDescription
idthe 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.

ParameterDescription
taskNamethe 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.

ParameterDescription
taskNamethe name to track this task under, without the app name prefix
functionNamethe name of the function to call
paramsthe 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.

ParameterDescription
taskNamethe name to track this task under, without the app name prefix
functionNamethe 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.

ParameterDescription
fifoKeya key shared by tasks that must be processed in submission order
functionNamethe name of the function to call
paramsthe 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.

ParameterDescription
taskNamethe name to track this task under, without the app name prefix, or null to skip tracking
fifoKeya key shared by tasks that must be processed in submission order
functionNamethe name of the function to call
paramsthe 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.

ParameterDescription
functionNamethe name of the function to call
paramsthe parameters to pass to the function
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.