trigger

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 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.

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