Skip to content

Timer and Scheduling Service

The Timer services can trigger events once, on an interval, or on a schedule.

Operations

Events


Configuration parameters

Please note that bold arguments are required, while italic arguments are optional.

Name Type Description
schedule object The task schedule definition
schedule.daily boolean This task should occur daily
schedule.hourly boolean This task should occur hourly
schedule.weekly boolean This task should occur weekly
schedule.yearly boolean This task should occur yearly
schedule.monthly boolean This task should occur monthly

Operations

Please note that bold arguments are required, while italic arguments are optional.

batchRetime

Restart countdown for 1 or more timers immediately. Works for one-time timers, recurring, and interval timers. For recurring/interval timers, they will restart countdown immediately while maining same setttings defined.

SRS-ID: S-TIMER-INT-003

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
timer_id [ string ] A list of timer id.

Responses

Code Body Type Description
200 object The operation completed successfully
default object An error occurred

Object Parameter of 200 response:

Name Type Description
result string Okay if successful

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

return Timer.batchRetime({timer_id={"timer1", "timer0"}})

cancel

Deletes an active timer immediately within the given solution.

SRS-ID: S-TIMER-INT-002

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
timer_id string The ID of the timer to cancel

Responses

Code Body Type Description
200 object The timer was deleted successfully. Note: if timer ID does not exist, it will still be marked as successfully deleted.
default object An error occurred

Object Parameter of 200 response:

Name Type Description
result string Okay if successful

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local req = Timer.sendAfter({timer_id="exampleId",duration=30})

cancelAll

Deletes all active timers immediately within the given solution.

SRS-ID: S-TIMER-INT-002

Responses

Code Body Type Description
200 object The operation completed successfully
default object An error occurred

Object Parameter of 200 response:

Name Type Description
result string Okay if successful

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

return Timer.cancelAll()

getEvents

Get timeout events with parameters in the solution

SRS-ID: S-TIMER-INT-002

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
start_time integer The unix epoch timestamp of the start time (in sec), should be within one month, default - seven days
end_time integer The unix epoch timestamp of the end time (in sec), should be within one month, default - current time
timer_id string Find by timer_ids. Each timer_id split by comma, default - get all timeout events

Responses

Code Body Type Description
200 object The operation completed successfully
default object An error occurred

Object Parameter of 200 response:

Name Type Description
list [ string ] A list of timers or timeout events information.
result string A message describing the result of the operation

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

return Timer.getEvents({timer_id = "testTimerId"})

list

Show a list of all active timers (one-time and recurring/interval) within the given solution.

SRS-ID: S-TIMER-INT-002

Responses

Code Body Type Description
200 object The operation completed successfully
default object An error occurred

Object Parameter of 200 response:

Name Type Description
list [ string ] A list of timers or timeout events information.
result string A message describing the result of the operation

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

return Timer.list()

retime

Restart countdown for 1 timer immediately. Works for one-time timers, recurring, and interval timers. For recurring/interval timers, they will restart countdown immediately while maining same setttings defined.

SRS-ID: S-TIMER-INT-003

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
timer_id string The ID of the timer

Responses

Code Body Type Description
200 object The operation completed successfully
default object An error occurred

Object Parameter of 200 response:

Name Type Description
result string Okay if successful

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

return Timer.retime({timer_id="timer1"})

sendAfter

Creates a 1-time timer that will fire after your defined duration time has passed.

SRS-ID: S-TIMER-INT-002

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
message string, object, array The message to send when the timer is hit. This message will be fired to Solution -> Service -> Timer, and user can handle this message there. This message will not show in the responses body; it depends on the Lua Scipt setting of the event. For example, the message will appear in the email subject.
duration integer The duration of the timer in seconds.
Maximum: 1000000000
Minimum: 30
timer_id string The ID of the timer. If null, it will be generated for you.

Responses

Code Body Type Description
200 object The timer was created successfully
default object An error occurred

Object Parameter of 200 response:

Name Type Description
result string A message describing the result of the operation
timer_id string The ID of the timer

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

return Timer.sendAfter({timer_id="abc123", duration=30})

sendInterval

Creates a recurring timer that will fire after your defined duration time has passed.

SRS-ID: S-TIMER-INT-002

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
message string, object, array The message to send when the timer is hit. This message will be fired to Solution -> Service -> Timer, and user can handle this message there. This message will not show in the responses body; it depends on the Lua Scipt setting of the event. For example, the message will appear in the email subject.
duration integer The duration of the timer in seconds.
Maximum: 1000000000
Minimum: 30
timer_id string The ID of the timer. If null, it will be generated for you.

Responses

Code Body Type Description
200 object The timer was created successfully
default object An error occurred

Object Parameter of 200 response:

Name Type Description
result string A message describing the result of the operation
timer_id string The ID of the timer

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

return Timer.sendInterval({timer_id="abc123", duration=30})

Events

timer

When a timer is timeout and triggered fired event, you can define how to handle the event. (E.g. sends an email to notifiy you of the timeout, print out which timer id expired for which solution… etc)

Arguments

request (object) - The timer task data

Name Type Description
timers [ object ] A list of timer events.
timers[].message string The message to send when the timer is hit.
timers[].timer_id string The ID of the timer. If null, it will be generated for you.
timers[].solution_id string The ID of the solution this timer is associated with.
solution_id string The ID of the solution this timer is associated with.

Example

--updates solution env on timer timeout
Config.updateEnv({
  timer_prompt = "timer event triggered for solution " .. request.solution_id
})
Config.updateEnv({
  timer_message = "timer message is " .. request.timers[1].message
})
Config.updateEnv({
  timer_timer_id = "timer id is " .. request.timers[1].timer_id
})

Service Health Check

Operations

/health

Enable the hosting system to check if service is active and running

SRS-ID: S-TIMER-INT-001

Arguments

No Content

Responses

Name Type Description
200 string OK

Errors

No content