Skip to main content

Real-time triggers (Evaluator)

Overview​

The Genesis Evaluator is a microservice used for triggering events.

You can configure two types of trigger:

  • scheduled events (Cron rules) are run automatically at the specified dates and times
  • data-driven events (Dynamic rules) are run when data in a table meets the rules you have specified

When a trigger happens, an event handler event message is sent, and its business logic is run. You must configure the required logic in the event. For example, it could update the data model, it could trigger the generation and publishing of a file, or it could trigger another event. By configuring the Evaluator and Event Handler, you can meet your exact business requirements.

Unlike most server capabilities in the Genesis Application Platform, you don't have to configure a .kts file to set up Evaluator; it is entirely driven by records in these two tables:

  • CRON_RULE for time-based (scheduled) events; you specify the schedule as a Quartz Cron Expression
  • DYNAMIC_RULE for data-update-driven events; you specify which value is to be monitored in a table or view, the boolean logic for triggering the event, and the event to be triggered

Example configuration​

Scheduled events​

Example CRON_RULE table entry:

NAMECRON_EXPRESSIONDESCRIPTIONTIME_ZONERULE_STATUSUSER_NAMEPROCESS_NAMEMESSAGE_TYPERESULT_EXPRESSION
US desk position report0 45 6 ? * MON-FRI *Send position report to US deskAmerica/New_YorkENABLEDadminPOSITION_EVENT_HANDLEREVENT_POSITION_REPORT(DESK = 'US')

In this example, the EVENT_POSITION_REPORT event will be triggered with DETAILS parameter DESK = 'US' at 06:45 AM (EST/EDT) each week day.

Given its name, we can expect this event to generate and distribute a report for a particular desk's positions.

Data-driven events​

IDNAMEDESCRIPTIONUSER_NAMERULE_TABLERULE_STATUSRULE_EXPRESSIONPROCESS_NAMEMESSAGE_TYPERESULT_EXPRESSIONTABLE_OPERATIONIS_TEMPLATERULE_EXECUTION_STRATEGYRULE_TYPE
000000000000001DRLO1Warn large tradeTrigger warning event on notional traded over 1,000,000adminTRADE_VIEWENABLED(NOTIONAL > 1000000)EVENT_LARGE_TRADE_WARNING(TRADE_ID = TRADE_ID)INSERTfalseONCE_PER_RECORD

In this example, the EVENT_LARGE_TRADE_WARNING will be triggered with DETAILS parameter of TRADE_ID == <the record's trade id> when the TRADE table (the root table of the TRADE_VIEW in our example data model) has a new record inserted where the NOTIONAL is greater than 1,000,000.

Given its name, we can expect this event to trigger some business workflow for large trades with the desk.

The Genesis Evaluator's DYNAMIC_RULE data-driven events are used to power the notifications and alert component.

Configuration options​

Here, we look look more closely at the two tables and values that we can expect in their records.

CRON_RULE​

Field NameDescriptionExample ValueMandatory
NAMEName of the rule. This is a key, and so each entry must have a unique valueUS desk position reporttrue
CRON_EXPRESSIONQuartz Cron Expression defining when the rule triggers0 45 6 ? * MON-FRI *true
DESCRIPTIONDescription of the ruleSend position report to US desktrue
TIME_ZONEThe Time Zone of the cron expression. Be careful selecting time zones that don't shift with daylight savings, such as EST, which may or may not be desirable.America/New_Yorktrue
RULE_STATUSThe status of the rule. If anything other than ENABLED, the rule will not listen or trigger any event.ENABLEDtrue
USER_NAMESet automatically to the user who inserts or amends the rule; any value you send is ignored. The rule's event runs as this user, so they must have permission to use that event for it to be triggered successfullyadminfalse
PROCESS_NAMEThe name of the process to send the resulting event. This is optional; service discovery will be used to find the process to send the event. This field can be omitted, and we recommend that you omit it to work in all environments, including those running compact processes, or for consul environmentsPOSITION_EVENT_HANDLERfalse
MESSAGE_TYPEThe name of the event the rule should send when triggeredEVENT_POSITION_REPORTtrue
RESULT_EXPRESSIONThe details to send on the event message. The syntax is that event fields should be left of the = and you can use literal values to the right. Multiple event fields are separated by &&(DESK = 'US') && (TRIGGER = 'RULE')true
warning

Since version 8.13, CRON_RULE records with an invalid CRON_EXPRESSION will not cause the Evaluator service to crash. These are detected on startup and a warning is written to the Evaluator logs instead. Ensure you monitor logs and correct any misconfigured cron rules.

The Evaluator schedules cron rules with Quartz Scheduler 2.4.1. This version handles nearest-weekday day-of-month expressions, such as 15W, correctly.

Rules are managed via the API, which exposes CRUD operations for maintaining the table.

DYNAMIC_RULE​

Field NameDescriptionExample ValueMandatory
IDID for the rule. Auto-generated where left unspecified on insert000000000000001DRLO1true
NAMEName of the ruleLarge tradetrue
DESCRIPTIONDescription of the ruleA large trade has been receivedtrue
USER_NAMESet automatically to the user who inserts or amends the rule; any value you send is ignoredadminfalse
RULE_TABLEThe table or view the rule listens to for updatesTRADE_VIEWtrue
RULE_STATUSThe status of the rule. If anything other than ENABLED, the rule will not listen or trigger any eventENABLEDtrue
RULE_EXPRESSIONBoolean logic for trigger. The expression can reference any of the fields on the updated table or view. The expression must be wrapped in brackets. It must be a non-blank Groovy expression that returns a Boolean. A blank RULE_EXPRESSION is rejected when you insert or amend the rule((NOTIONAL > 1000000))true
PROCESS_NAMEThe name of the process to send the resulting event. As of v8, this is optional; service discovery will be used to find the process to send the event. This field can be omitted, and we recommend that you omit it to work in all environments, including those running compact processes, or for consul environmentsPOSITION_EVENT_HANDLERfalse
MESSAGE_TYPEThe name of the event the rule should send when triggeredEVENT_LARGE_TRADE_WARNINGtrue
RESULT_EXPRESSIONThe details to send on the event message. The syntax is that event fields should be left of the = and you can use literal values or field values from the RULE_TABLE to the right. Multiple event fields are separated by &&. The field must be present, but a blank value is accepted(TRADE_ID = TRADE_ID) && (TRIGGER = 'RULE')true
TABLE_OPERATIONThe table operation to trigger the rule on. It takes a single value: INSERT, MODIFY, DELETE or PRIME (see below). If you omit it on insert, it defaults to INSERT; on amend it is mandatoryINSERTtrue
IS_TEMPLATERelevant when using notifications and alert component where users can define rule templates to which users subscribe. Rules marked as true are templates, are never triggered (a subscription to a template creates a new dynamic rule)false
RULE_EXECUTION_STRATEGYDefines how many times the rule should trigger for a given record (record of root table where RULE_TABLE is a view). Valid values are UNLIMITED, ONCE_ONLY, ONCE_PER_RECORD. Default is UNLIMITED. This is helpful if TABLE_OPERATION must include MODIFY and the records may have many modifications to stop repeated alertsONCE_ONLYfalse
RULE_TYPEUsed to specify that this rule belongs to a group. For example, the notifications and alert component will set this value to NOTIFYNOTIFYfalse

PRIME makes the rule fire for rows that already exist in the watched table when the Evaluator starts watching it: at Evaluator startup, or when the first rule for that table is registered. Without PRIME, existing rows are ignored. A PRIME rule fires again on those rows after every Evaluator restart, unless RULE_EXECUTION_STRATEGY prevents repeats: ONCE_PER_RECORD is remembered across restarts, and ONCE_ONLY deletes the rule after its first fire.

Rules are managed via the API, which exposes CRUD operations for maintaining the table. Components such as notifications and alert component include a user interface that manages dynamic rule set-up and reads application metadata to help users populate table/view selection and expressions.

Expression limits​

From version 10.0.1, the insert and amend events check a rule's expressions against the expression limits before they save it: RULE_EXPRESSION and RESULT_EXPRESSION for a dynamic rule, and RESULT_EXPRESSION for a cron rule. An expression over a limit is rejected with a message that names the limit, for example Expression exceeds ExpressionMaxNestingDepth: 101 > 100.

  • An amend only checks an expression whose value differs from the stored rule, so you can still amend the other fields of a stored rule that is over the limits.
  • A template (IS_TEMPLATE is true) isn't checked when you insert or amend it. The rule created from it is checked when a user subscribes to the template.
  • Rule expressions also get a nesting check on the parsed expression, capped at 100 levels. ExpressionMaxNestingDepth can lower that cap, but can't raise or disable it. This check counts nested operators and method calls, not brackets, so a flat chain of more than about 100 && or || conditions is refused with Nesting deeper than 100 levels is not allowed in a dynamic rule, even though it is within ExpressionMaxLogicalOperators.
  • Rules already in the database keep running when the Evaluator loads them, even if they are over the three limits; the Evaluator logs a warning for each one. The nesting check on the parsed expression still applies at its fixed cap of 100 levels, so a stored rule nested more deeply than that isn't run.

Audit tables​

Every change to a rule is recorded: cron rules in CRON_RULE_AUDIT, dynamic rules in DYNAMIC_RULE_AUDIT. Both are standard audit tables, and the Evaluator writes the audit record together with the change. Enabling or disabling a rule is recorded as a MODIFY.

Each audit record holds the rule's fields, plus these fields:

Field NameDescription
CRON_RULE_AUDIT_ID / DYNAMIC_RULE_AUDIT_IDGenerated ID of the audit record
AUDIT_EVENT_TYPEINSERT, MODIFY or DELETE. In DYNAMIC_RULE_AUDIT it can also be ONCE_ONLY_DYNAMIC_RULE_EXECUTION, when a ONCE_ONLY rule fires and the Evaluator deletes it
AUDIT_EVENT_DATETIMEDate and time of the change
AUDIT_EVENT_USERThe user who sent the event that changed the rule. On a ONCE_ONLY_DYNAMIC_RULE_EXECUTION row in DYNAMIC_RULE_AUDIT, this is the rule's USER_NAME
AUDIT_EVENT_TEXTNot set by the Evaluator in CRON_RULE_AUDIT. In DYNAMIC_RULE_AUDIT it is set on a ONCE_ONLY_DYNAMIC_RULE_EXECUTION row to Rule <id> with execution strategy ONCE_ONLY executed, deleting rule

USER_NAME is the rule's own USER_NAME; the user who made the change is in AUDIT_EVENT_USER.

Upgrading from 8.15​

warning

In 8.15 and earlier, CRON_RULE_AUDIT had EVENT_TYPE and EVENT_DATETIME instead of AUDIT_EVENT_TYPE and AUDIT_EVENT_DATETIME, and its USER_NAME held the user who made the change. DYNAMIC_RULE_AUDIT is unchanged. Update any queries or reports that read those columns.

Existing rows are migrated to the new columns when you upgrade to 10.0; their audit IDs are regenerated. On Docker upgrades the rows are exported, cleared and reloaded automatically. On non-Docker upgrades the pre-install hook exports the rows to a CSV file and clears the table. After remap --commit, run genesisInstallHooks with --hookType=POST_REMAP to load them back, and keep the exported file until then. The migration copies each old USER_NAME into both AUDIT_EVENT_USER and USER_NAME, so on rows written before the upgrade USER_NAME is still the user who made the change, not the rule's user.

Client API​

Rules can be managed via the API.

REST requests go to the Genesis Router, which listens on port 9064 by default. The Router forwards the EVENT_CRON_RULE_* and EVENT_DYNAMIC_RULE_* events to the GENESIS_EVALUATOR process, so the Evaluator must be running; see Runtime configuration.

In the examples below, responses are omitted for brevity; they are standard eventHandler acks/nacks.

CRON_RULE API​

EVENT_CRON_RULE_INSERT​

Insert a new Cron Rule.

All parameters, descriptions and defaults are listed under CRON_RULE configuration options

{
"USER_NAME": "admin",
"SOURCE_REF": "001",
"MESSAGE_TYPE": "EVENT_CRON_RULE_INSERT",
"DETAILS": {
"NAME" : "US desk position report",
"CRON_EXPRESSION" : "0 45 6 ? * MON-FRI *",
"DESCRIPTION" : "Send position report to US desk",
"TIME_ZONE" : "America/New_York",
"RULE_STATUS" : "ENABLED",
"PROCESS_NAME" : "POSITION_EVENT_HANDLER",
"MESSAGE_TYPE" : "EVENT_POSITION_REPORT",
"RESULT_EXPRESSION" : "(DESK = 'US')"
}
}

EVENT_CRON_RULE_AMEND​

Amend an existing rule.

Changing the time to 7am from example above.

All parameters, descriptions and defaults are listed under CRON_RULE configuration options

{
"USER_NAME": "admin",
"SOURCE_REF": "002",
"MESSAGE_TYPE": "EVENT_CRON_RULE_AMEND",
"DETAILS": {
"NAME" : "US desk position report",
"CRON_EXPRESSION" : "0 45 6 ? * MON-FRI *",
"DESCRIPTION" : "Send position report to US desk",
"TIME_ZONE" : "America/New_York",
"RULE_STATUS" : "ENABLED",
"PROCESS_NAME" : "POSITION_EVENT_HANDLER",
"MESSAGE_TYPE" : "EVENT_POSITION_REPORT",
"RESULT_EXPRESSION" : "(DESK = 'US')"
}
}

EVENT_CRON_RULE_DELETE​

Delete an existing rule. Send only NAME; any other field is rejected.

{
"USER_NAME": "admin",
"SOURCE_REF": "003",
"MESSAGE_TYPE": "EVENT_CRON_RULE_DELETE",
"DETAILS": {
"NAME" : "US desk position report"
}
}

EVENT_CRON_RULE_ENABLE​

Enable an existing rule. Send only NAME; any other field is rejected.

{
"USER_NAME": "admin",
"SOURCE_REF": "004",
"MESSAGE_TYPE": "EVENT_CRON_RULE_ENABLE",
"DETAILS": {
"NAME" : "US desk position report"
}
}

EVENT_CRON_RULE_DISABLE​

Disable an existing rule. Send only NAME; any other field is rejected.

{
"USER_NAME": "admin",
"SOURCE_REF": "005",
"MESSAGE_TYPE": "EVENT_CRON_RULE_DISABLE",
"DETAILS": {
"NAME" : "US desk position report"
}
}

DYNAMIC_RULE API​

EVENT_DYNAMIC_RULE_INSERT​

Insert a new dynamic rule.

All parameters, descriptions and defaults are listed under DYNAMIC_RULE configuration options

{
"USER_NAME": "admin",
"SOURCE_REF": "006",
"MESSAGE_TYPE": "EVENT_DYNAMIC_RULE_INSERT",
"DETAILS": {
"NAME" : "Warn large trade",
"DESCRIPTION" : "Trigger warning event on notional traded over 1,000,000",
"USER_NAME" : "admin",
"RULE_TABLE" : "TRADE_VIEW",
"RULE_STATUS" : "ENABLED",
"RULE_EXPRESSION" : "(NOTIONAL > 1000000)",
"MESSAGE_TYPE" : "EVENT_LARGE_TRADE_WARNING",
"RESULT_EXPRESSION" : "(TRADE_ID = TRADE_ID)",
"TABLE_OPERATION" : "INSERT",
"IS_TEMPLATE" : "true",
"RULE_EXECUTION_STRATEGY" : "ONCE_PER_RECORD"
}
}

EVENT_DYNAMIC_RULE_AMEND​

Amend an existing rule.

Changing the rule to trigger on modifications to the record instead of inserts.

All parameters, descriptions and defaults are listed under DYNAMIC_RULE configuration options

An amend replaces every editable field of the rule, so send the whole rule each time. An amend that leaves out a mandatory field is rejected with a validation error, and nothing is cleared. TABLE_OPERATION is mandatory and takes one value: INSERT, MODIFY, DELETE or PRIME (see DYNAMIC_RULE for what PRIME does). RULE_STATUS, RULE_TYPE, IS_TEMPLATE and RULE_EXECUTION_STRATEGY are ignored on amend, and USER_NAME is always set to the user who sends the event.

{
"USER_NAME": "admin",
"SOURCE_REF": "007",
"MESSAGE_TYPE": "EVENT_DYNAMIC_RULE_AMEND",
"DETAILS": {
"ID" : "000000000000001DRLO1",
"NAME" : "Warn large trade",
"DESCRIPTION" : "Trigger warning event on notional traded over 1,000,000",
"RULE_TABLE" : "TRADE_VIEW",
"RULE_EXPRESSION" : "(NOTIONAL > 1000000)",
"MESSAGE_TYPE" : "EVENT_LARGE_TRADE_WARNING",
"RESULT_EXPRESSION" : "(TRADE_ID = TRADE_ID)",
"TABLE_OPERATION" : "MODIFY"
}
}

EVENT_DYNAMIC_RULE_DELETE​

Delete an existing rule. Send only ID; any other field is rejected.

{
"USER_NAME": "admin",
"SOURCE_REF": "008",
"MESSAGE_TYPE": "EVENT_DYNAMIC_RULE_DELETE",
"DETAILS": {
"ID" : "000000000000001DRLO1"
}
}

EVENT_DYNAMIC_RULE_ENABLE​

Enable an existing rule. Send only ID; any other field is rejected.

{
"USER_NAME": "admin",
"SOURCE_REF": "009",
"MESSAGE_TYPE": "EVENT_DYNAMIC_RULE_ENABLE",
"DETAILS": {
"ID" : "000000000000001DRLO1"
}
}

EVENT_DYNAMIC_RULE_DISABLE​

Disable an existing rule. Send only ID; any other field is rejected.

{
"USER_NAME": "admin",
"SOURCE_REF": "010",
"MESSAGE_TYPE": "EVENT_DYNAMIC_RULE_DISABLE",
"DETAILS": {
"ID" : "000000000000001DRLO1"
}
}

Runtime configuration​

The Evaluator runs by default. The platform defines the GENESIS_EVALUATOR process in its own genesis-processes.xml with <start>true</start> and <primaryOnly>true</primaryOnly>, and its service definition (port 9015) is already in the platform's service definitions, so you do not need to configure anything to use it.

If your project was generated by genx, it contains commented-out GENESIS_EVALUATOR blocks in <app>-processes.xml and <app>-service-definitions.xml. Leave them commented. Uncommenting them declares the process a second time and the build fails with Multiple processes 'GENESIS_EVALUATOR' for the service definition declared.

To turn the Evaluator off, or to change primaryOnly, override the genesis-processes.xml file in your application and change the GENESIS_EVALUATOR entry (for example, set <start> to false). During your next build or genesisInstall, the change will show up in your list of processes.

important

Evaluator should be left set to <primaryOnly>true</primaryOnly>; otherwise, if deployed into a multi-node environment, events will be triggered multiple times.