Events and actions: terminology
Events and actions can give your application behavior beyond the create read update delete (CRUD) style application. Use events and actions to:
- Make a complex, context sensitive changes to the database in response to explicit or implicit user action
- Communicate with the world outside your application: send emails or send messages to message brokers
- Respond to incoming messages from message brokers or sensors
- Monitor your application: record startup, user logins, errors and respond to those.
Events and actions have a specific terminology in Saltcorn:
An event is an indication that something happened at a particular time. Every event has an event type, which indicates what kind of thing happened and a time of the occurrence. This time is a point in time, i.e. the event does not have a duration. An event may also be associated with: a user; a channel and a payload (associated data). For events tied to the database, the channel will be the table name and the payload will be the database row.
The event type is a short text string indicating what kind of event occurred. For instance, for the database associated events, there are events for inserting (“Insert”), deleting (“Delete”) and updating (“Update”) rows. Other event types are not associated with the database, such as events for periodic occurrences, for instance the Hourly event. You can create your own event types in the user interface, called Custom events, and event types may also be supplied by plugins as in the case of a plug-in that provides interoperability with a message broker. Some event types are always associated with a channel (table name in the case of database events), others are not
An action is something your application can do in response to an event or a button in the user interface. Most of the events do one specific thing, like send an email or activate a webhook. Plugins can supply new actions. The most flexible actions, blocks and run_js_code can perform complex programmable actions using Visual programming language or JavaScript code, respectively. Some actions, such as sending email, require a row from the database (because emails are formed based on views).
A trigger is an association of an event type with an action, causing that action to be run in response to that specific trigger. If the event type associated with channels or tables, then the trigger may run only in response to a specified channel/table.
Events can be stored in the event log. This is a permanently stored list of events that have occurred in the past. You may not want to log all events, so the event log settings allow you to choose which events are logged by their type.