Skip to content

Repeat Node

Jens Rossbach edited this page Jun 16, 2024 · 18 revisions

The repeat node forwards an incoming message upon reception (optionally) and then periodically sends out this messages according to the configured interval/schedule. The repetition ends when a new message is received and optionally at a specific time.

Repeat Node

Configuration

On the configuration page, various settings of the node can be configured.

General

General Configuration

Name

The name is optional and can be used to better distinguish different repeat nodes. If omitted, the configured interval is displayed on the node instance.

Configuration

The configuration node to be used must be selected here.

Repetition

Repetition can be scheduled in either a simple, an advanced or a custom mode.

Simple Mode

Simple Mode

In simple mode, message sending repetition is defined through an interval time which can be expressed in seconds, minutes or hours.

Advanced Mode

Advanced Mode

In advanced mode, message sending repetition is defined through a cron-like schedule. The format of the cron table must be according to the CronosJS expression syntax.

Please note that the intervals are aligned to absolute time boundaries which means the first interval after scheduling is likely to be shorter than the consecutive intervals. Example: If you have a cron table of */5 * * * *, which means "every 5 minutes", and a message is received at 09:03, then the first repetition will be at 09:05, then at 09:10, then at 09:15 and so on. Hence the first interval has only 2 minutes instead of 5. If you don't want such behavior, you have to use the simple or custom mode.

Custom Mode

Custom Mode JSONata

In custom mode, message sending repetition can be defined through a JSONata expression. The expressions are evaluated at every iteration and must result in a time value expressed as either a string or a number. Any property of the repeated input message can be accessed in the expressions. Additionally there are some common expression variables provided.

The following table describes how the expression result is interpreted.

Type Range Description
String Point in time must be at least one second from now and must not be more than one week in the future. String representation of the absolute date and time of the next repetition. The string must follow the basic format as described in section Time Input. For time-only values the date of the current day is applied.
Number 1000 ≤ n ≤ 604800000 The relative time span in milliseconds until the next repetition.
Number now + 1000 ≤ n ≤ now + 604800000 The absolute date and time of the next repetition in milliseconds elapsed since the UNIX epoch.

Any value outside of the ranges given above leads to an error.

Alternatively, the repetition can be taken from an environment or context variable or an arbitrary property of the input message. The format of the variables/properties is the same as for the override properties interval and crontab from the input message, see section Input for more information. The node detects the repeat mode (simple or advanced) automatically based on the variable/property format.

Custom Mode Context

Until

The condition when periodic message sending should stop. A subsequently received message always stops the repetition of the previous message.

Until Specific Time

If next message is selected, this will be the only stop condition.

Otherwise a specific point in time can be configured as additional ending condition according to description in section Time Input or a JSONata expression can be specified which must result in either true (stop condition is reached) or false (stop condition is not yet reached). Within the JSONata expression, the time of the next repetition can be accessed through expression variable $next.

Alternatively, the repetition stop condition can be taken from an environment or context variable or an arbitrary property of the input message. The content of such an environment/context variable or message property must follow the basic, extended or structured input format as described in section Time Input.

The following attributes are only available if a specific ending time has been selected.

Date

Any date entered or selected here is used as the date when the ending time applies. The entered value must be in the form YYYY-MM-DD. If no date is provided, the ending time is assumed to be at the same date at which the input message has been received.

Offset

An offset can be specified which will be added to or subtracted from the ending time. The offset must be entered in minutes and can be in the range of -300 to +300. If the checkbox on the right side is selected, the offset will be randomized between 0 and the specified value.

Options

The option When message arrives on input allows to fine-tune the behavior on message ingress. The override column specifies the value that has to be used in the msg.ingress property for overriding the configuration.

Option Override Description
do nothing noop The message is not forwarded on reception, next sending of the message happens after the first interval has passed (provided that the end condition has not been reached at that time).
forward message forward The message is immediately forwarded on reception provided that the end time is not exceeded or no end time has been set.
forced forward message forward:forced The message is immediately forwarded on reception regardless if the end time has been exceeded or not. This means it is ensured that an incoming message is forwarded at least once in all circumstances.

If the option Preserve control properties in messages is selected, control properties as described in section Input below are not deleted from forwarded input messages and hence still be present in the messages when they are sent to the output port.

If the option Ignore control properties in messages is selected, control properties as described in section Input below are ignored. This is useful if messages to be repeated contain properties with the same names as the control properties and hence prevents their misinterpretation.

Input

The input message is forwarded as is but can also control the repetition behavior of the node. For this purpose, the following so called control properties can be added to a message:

Property Type Description
stop Any If present, message sending repetition is immediately stopped. The message containing this property is discarded.

Additionally some configuration of the node can be overridden by specifying one of the following properties in the input message:

Property Type Description
interval Object Overrides the interval for message sending repetition.
crontab String Overrides the cron table for message sending repetition.
until Object Overrides the condition when message sending repetition should end.
ingress String Overrides the behavior on message ingress. See section Options for possible values.

If a property called interval is present in the input message, the interval for repetition is overridden. The property must have the following content:

Property Type Description
value Number The duration of the interval.
unit String The unit for the interval duration, which can be one of "seconds", "minutes" or "hours".

The presence of property interval in the input message switches the repeat node to simple mode. The presence of property crontab switches to advanced mode respectively. If multiple of these properties are present in the input message, property crontab takes precedence over property interval.

If a property called until is present in the input message, the condition when message sending repetition should end is overridden. The property may be null, in this case the repetition ends only upon reception of the next message (this is equal to selecting next message as condition in the configuration UI). The format of the property until must follow the structured input format as described in section Time Input. Additionally, the repeat node supports the property until.date containing the date of the ending time in the form YYYY-MM-DD.

Please note that the above control and override properties only affect the behavior and repetition of the input message in which they are actually contained.

Examples

The following examples are JSON representations of the complete input message.

Explicitly stops repeating the previously received message:

{
    "stop": true
}

Repeats this message every 5 minutes (independent from configuration):

{
    "topic":   "my/holy/message",
    "payload": 42,
    "interval":
    {
        "value": 5,
        "unit":  "minutes"
    }
}

Repeats this message every half hour from Monday to Friday (independent from configuration):

{
    "topic":   "my/advanced/message",
    "payload": "Hero",
    "crontab": "*/30 * * * Mon-Fri"
}

Repeats this message according to configured interval until sunset minus 15 minutes (randomized):

{
    "payload": "My repeating message",
    "until":
    {
        "type":   "sun",
        "value":  "sunset",
        "offset": -15,
        "random": true
    }
}

Repeats this message every 2 seconds until next message is received (independent from configured ending time):

{
    "payload": true,
    "interval":
    {
        "value": 2,
        "unit":  "seconds"
    },
    "until": null
}

Forwards incoming message upon reception in all circumstances:

{
    "payload": "May the Force be with you",
    "ingress": "forward:forced"
}

Outputs

Messages are sent to the output upon reception (optionally) and periodically until the next message or a message with the property stop has been received. If configured, message sending repetition also ends when the ending time has been reached.