trigger

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Trigger node

Type: trigger
Category: Flow Control

Sends one message immediately, then optionally a second after a delay.

Behavior

This node is registered as trigger and runs as part of a workflow. Its exact runtime behavior is implemented in node.go; this document summarizes the editor-facing purpose and configuration contract.

Configuration

Field Type Default Description
bytopic boolean false Separate Timers per Topic — Keep an independent timer per message topic
duration number 250 Delay — Delay before the second output fires; negative = resend every interval, 0 = wait to be reset
extend boolean false Extend on New Message — Restart the pending timer when a new message arrives
op1 string First Output — Value sent immediately on output 1 (parsed per op1type)
op1type string str First Output Type
op2 string Second Output — Value sent after the delay (parsed per op2type)
op2type string str Second Output Type
outputs integer 2 Outputs — 2 sends the delayed output on a second port; 1 reuses output 1
overrideDelay boolean false Override via msg.delay — Let the message's delay metadata replace the configured delay (same units)
reset string Reset Payload — A message whose payload equals this value resets the trigger (msg.reset always does)
resetValue string Reset Value — Alias for reset — a message whose payload equals it resets the trigger
then string wait Then — wait: send the second output after the delay; loop: resend the first output every interval until reset; block: wait to be reset (imported flows also derive the mode from the delay sign — negative = resend, zero = wait to be reset)
units string ms Units

Implementation

  • node.go contains the executor, validation, schema, and registration.
  • editor.html contains the editor integration.
  • node_test.go, when present, contains behavioral tests.

Documentation

Overview

Package trigger contains the trigger node implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TopicScope added in v0.7.0

type TopicScope bool

TopicScope decodes Node-RED's bytopic representations into a bool: exported flows carry the enum strings "topic" (per-topic timers) and "all" (one shared timer), while the editor schema writes booleans. true means per-topic.

func (*TopicScope) UnmarshalJSON added in v0.7.0

func (s *TopicScope) UnmarshalJSON(raw []byte) error

UnmarshalJSON accepts the enum strings, booleans and boolean strings.

type TriggerConfig

type TriggerConfig struct {
	// Op1 / Op1Type configure the value emitted immediately on output_1.
	// Types: str (default) | num | bool | json | payload (pass input
	// through) | date (current timestamp ms) | bin (JSON byte array or
	// base64) | env (environment variable).
	Op1     string `json:"op1"`
	Op1Type string `json:"op1type"`
	// Op2 / Op2Type configure the value emitted when the timer expires.
	Op2     string `json:"op2"`
	Op2Type string `json:"op2type"`
	// Then selects the follow-up mode: "wait" (default, send op2 after
	// the delay), "loop" (resend op1 every interval until reset) or
	// "block" (wait to be reset — further messages are dropped until a
	// reset or the delay expires). Node-RED serializes the mode through
	// the Duration sign instead: negative = loop, zero = block; an
	// empty Then falls back to that convention.
	Then string `json:"then"`
	// Duration is the delay before op2 fires (in Units). Node-RED
	// encodes the then-mode in its sign: negative = resend every
	// |Duration|, zero = wait to be reset.
	Duration float64 `json:"duration"`
	// Units is the duration unit: ms (default) | s | min | hr.
	Units string `json:"units"`
	// Extend restarts the pending timer on each new message.
	Extend bool `json:"extend"`
	// OverrideDelay lets Metadata["delay"] replace the configured
	// duration (same units).
	OverrideDelay bool `json:"overrideDelay"`
	// Outputs selects where op2 goes: 1 = output_1, 2 = output_2.
	Outputs int `json:"outputs"`
	// ByTopic keeps a separate timer per Metadata["topic"].
	ByTopic TopicScope `json:"bytopic"`
	// Reset is Node-RED's reset field: a message whose payload
	// stringifies to this value resets pending timers (in addition to
	// msg.reset).
	Reset string `json:"reset"`
	// ResetValue is an accepted alias for Reset.
	ResetValue string `json:"resetValue"`
}

TriggerConfig holds configuration for the trigger node — the Node-RED trigger equivalent (simplified field names).

type TriggerNode

type TriggerNode struct {
	*nodebase.BaseNode
	// contains filtered or unexported fields
}

TriggerNode sends one message immediately, then optionally a second after a configurable delay — the Node-RED trigger node. The immediate output always routes to output_1 (via SelectPorts); the delayed output is emitted asynchronously on output_2 (outputs=2) or output_1. Metadata["reset"] clears pending timers and drops the message.

func NewTriggerNode

func NewTriggerNode(node nodestore.NodeInterface, config *TriggerConfig, host nodebase.NodeHost) *TriggerNode

NewTriggerNode creates a new trigger node

func (*TriggerNode) Execute

Execute emits op1 immediately (returned as the output, routed to output_1 by SelectPorts) and arms/rearms the follow-up per the then-mode: wait (op2 after the delay), loop (resend op1 every interval until reset) or block (drop further messages until a reset or the delay expires). A truthy Metadata["reset"] — or a payload equal to the configured reset value — clears the topic and drops the message.

func (*TriggerNode) SelectPorts

func (n *TriggerNode) SelectPorts(input, output nodestore.MessageInterface) []string

SelectPorts routes the immediate output (op1) to output_1 only.

func (*TriggerNode) Validate

func (n *TriggerNode) Validate() error

Validate checks the trigger node configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL