Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

State Machine Definition Context

Anthony Clavio edited this page Nov 24, 2020 · 2 revisions

State Conductor state machine definitions use a "context" to define the set of documents to which they will be automatically applied. Document's with the state-conductor-item collection that are inserted or modified in MarkLogic will be evaluated against each installed State Machine definition's context(s); for each State Machine who's context matches a State Conductor Execution document will be created. The Execution document will cause the triggering document to be processed by the matching State Machine.

Supported Context Scopes:

  1. Collection
  2. Directory
  3. Query Based
  4. Scheduled
  5. Event

Collection Scope

Matches documents based on MarkLogic collections. The "value" will be used as a cts.collectionQuery().

{
  "scope": "collection",
  "value": "example"
}

Directory Scope

Matches documents based on MarkLogic directory. The "value" will be used as a cts.directoryQuery().

{
  "scope": "directory",
  "value": "/example/"
}

Query Scope

Matches documents based on a query. The "value" should string containing a JSON serialized query; it will be deserialized and passed to a cts.query().

{
  "scope": "query",
  "value": "{\"andQuery\":{\"queries\":[{\"collectionQuery\":{\"uris\":[\"example\"]}}, {\"elementValueQuery\":{\"element\":[\"name\"], \"text\":[\"Jane Doe\"], \"options\":[\"lang=en\"]}}]}}"
}

You can use the following QConsole script to generate a serialized JSON string of a cts query:

'use strict';

let query = cts.andQuery([
  cts.collectionQuery('example'),
  cts.elementValueQuery('name', 'Jane Doe'),
]);

xdmp.toJSON(query).toString();

Scheduled Scope

Executes a state machine based on a scheduled period of time. This is unique as document operations will not trigger this state machine. Therefore the executions created by this state machine will not reference a document's uri.

Supported scheduled values include minutely, hourly, daily, weekly, monthly, and once.

example: executes once every five minutes

{
  "scope": "scheduled",
  "value": "minutely",
  "period": 5
}

example: executes once every two hours at 30 minutes past the hour

{
  "scope": "scheduled",
  "value": "hourly",
  "period": 2,
  "minute": "30"
}

example: executes once every other day at 10pm

{
  "scope": "scheduled",
  "value": "daily",
  "period": 2,
  "startTime": "22:00"
}

example: executes every week on Mondays, Wednesdays, at Fridays at noon

{
  "scope": "scheduled",
  "value": "weekly",
  "period": 1,
  "days": ["monday", "wednesday", "friday"],
  "startTime": "12:00"
}

example: executes every other month on the 28th day of the month at 10pm

{
  "scope": "scheduled",
  "value": "monthly",
  "period": 2,
  "monthDay": 28,
  "startTime": "22:00"
}

example: executes one time only on January 31st 2030 at 2am

{
  "scope": "scheduled",
  "value": "once",
  "startDate": "01/31/2030",
  "startTime": "02:00"
}

Event Scope

(added in 0.6.0)

Executes a state machine when even the configured event is emitted. This is unique as document operations will not trigger this state machine. Therefore the executions created by this state machine will not reference a document's uri.

example: executes when the notification event is emitted

{
  "scope": "event",
  "value": "notification"
}

Clone this wiki locally