Trigger
A Trigger Business Object runs code when something happens: manually, on a timer, when a mail arrives, when a file changes, or when an Entity changes. In code, each Trigger is a class with static methods under This.$Trigger.<TriggerName>: execute() runs the Trigger’s code directly, and timer and file Triggers can be started and stopped.
Availability: Server
How to reach it
Section titled “How to reach it”This.$Trigger.<TriggerName>Triggers are grouped under the $Trigger namespace. This.<TriggerName> does not work; the $Trigger. part is required.
Which methods a Trigger has depends on its trigger type:
| Trigger type | Methods |
|---|---|
manual | execute() |
timer | execute(), start(), stop(), isRunning() |
mail | execute() |
file | execute(), start(), stop(), isRunning() |
entityChange | none |
Note
This.$Trigger is also typed in shared code (Entity methods with availability serverAndClient or calculation), but it exists only on the server. When shared code runs on the client, This.$Trigger is undefined.
Functions
Section titled “Functions”execute()
Section titled “execute()”// manualexecute(): Promise<void>// timerexecute(executionDate?: Date): Promise<void>// mailexecute(mail: Sys.Types.Mail, imap: SimpleImap): Promise<void>// fileexecute(eventName: WatcherEventName, path: string, watcher?: Stats): Promise<void>Runs the Trigger’s code once, immediately, with the given arguments. The call does not depend on whether the Trigger is running.
| Parameter | Trigger type | Type | Description |
|---|---|---|---|
executionDate | timer | Date | The time the run is for. Default: now. |
mail | mail | Sys.Types.Mail | The mail to process. |
imap | mail | SimpleImap | The IMAP connection the mail came from. |
eventName | file | WatcherEventName | The kind of file system change. |
path | file | string | Absolute path of the changed file or directory. |
watcher | file | Stats | The file’s Node.js fs.Stats. If omitted, Lowgile reads them from path, and the call throws if path no longer exists. |
Returns: Promise<void> · Availability: Server
start()
Section titled “start()”start(): voidStarts a timer or file Trigger and saves it as active, so it also runs after a restart.
Returns: void · Availability: Server
Note
start() returns before the change is saved. isRunning() called right after it can still return false.
stop()
Section titled “stop()”stop(): voidStops a timer or file Trigger and saves it as inactive.
Returns: void · Availability: Server
Note
stop() returns before the change is saved. isRunning() called right after it can still return true.
isRunning()
Section titled “isRunning()”isRunning(): booleanTells whether a timer or file Trigger is active. Returns false if the Trigger is not known to the Trigger manager.
Returns: boolean · Availability: Server
WatcherEventName
Section titled “WatcherEventName”type WatcherEventName = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'The kind of change a file Trigger reacts to: a file or directory was added, a file changed, or a file or directory was removed.
Availability: Server