feat: enhance notification mustache syntax with workflow description

This commit is contained in:
Fu Diwei
2026-04-30 18:55:07 +08:00
committed by RHQYZ
parent 85f214d73b
commit e6b9d6bdb2
5 changed files with 19 additions and 12 deletions
+7 -5
View File
@@ -316,11 +316,13 @@ func (wd *workflowDispatcher) tryExecuteAsync(task *taskInfo) {
// 执行工作流
wd.syslog.Info(fmt.Sprintf("workflow #%s's run #%s started", task.WorkflowId, task.RunId))
we.Invoke(task.ctx, engine.WorkflowExecution{
WorkflowId: workflowRun.WorkflowId,
WorkflowName: workflow.Name,
RunId: workflowRun.Id,
RunTrigger: workflowRun.Trigger,
Graph: workflowRun.Graph,
WorkflowId: workflow.Id,
WorkflowName: workflow.Name,
WorkflowDescription: workflow.Description,
RunId: workflowRun.Id,
RunTrigger: workflowRun.Trigger,
RunAt: workflowRun.StartedAt,
Graph: workflowRun.Graph,
})
wd.syslog.Info(fmt.Sprintf("workflow #%s's run #%s stopped", task.WorkflowId, task.RunId))
}
+9 -5
View File
@@ -7,6 +7,7 @@ import (
"log/slog"
"runtime/debug"
"sync"
"time"
"github.com/samber/lo"
@@ -17,11 +18,13 @@ import (
)
type WorkflowExecution struct {
WorkflowId string
WorkflowName string
RunId string
RunTrigger domain.WorkflowTriggerType
Graph *Graph
WorkflowId string
WorkflowName string
WorkflowDescription string
RunId string
RunTrigger domain.WorkflowTriggerType
RunAt time.Time
Graph *Graph
}
type WorkflowEngine interface {
@@ -71,6 +74,7 @@ func (we *workflowEngine) Invoke(ctx context.Context, execution WorkflowExecutio
wfVars := newVariableManager()
wfVars.Set(stateVarKeyWorkflowId, execution.WorkflowId, stateValTypeString)
wfVars.Set(stateVarKeyWorkflowName, execution.WorkflowName, stateValTypeString)
wfVars.Set(stateVarKeyWorkflowDescription, execution.WorkflowDescription, stateValTypeString)
wfVars.Set(stateVarKeyRunId, execution.RunId, stateValTypeString)
wfVars.Set(stateVarKeyRunTrigger, execution.RunTrigger, stateValTypeString)
wfVars.Set(stateVarKeyErrorNodeId, "", stateValTypeString)
+1
View File
@@ -292,6 +292,7 @@ const (
const (
stateVarKeyWorkflowId = "workflow.id" // ValueType: "string"
stateVarKeyWorkflowName = "workflow.name" // ValueType: "string"
stateVarKeyWorkflowDescription = "workflow.description" // ValueType: "string"
stateVarKeyRunId = "run.id" // ValueType: "string"
stateVarKeyRunTrigger = "run.trigger" // ValueType: "string"
stateVarKeyNodeId = "node.id" // ValueType: "string"
@@ -1279,7 +1279,7 @@
"workflow_node.notify.form.subject.placeholder": "Please enter subject",
"workflow_node.notify.form.message.label": "Message",
"workflow_node.notify.form.message.placeholder": "Please enter message",
"workflow_node.notify.form.template.guide": "<details><summary>The content using the \"Mustache\" syntax (double curly braces) and preceded by \"$\" in the subject or message are text interpolations. They will be replaced by the actual values. </summary><br>Supported text interpolations: <ol style=\"list-style: disc;\"><li>Workflow: <ol style=\"margin: 0; list-style: '-';\"><li><em>workflow.id</em>: The ID of the workflow.</li><li><em>workflow.name</em>: The name of the workflow.</li><li><em>run.id</em>: The ID of the workflow run.</li></ol></li><li>Error: <br><i>(If there are multiple nodes that have failed before this, it always indicate the nearest one.)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>error.nodeId</em>: The node ID that execution failed.</li><li><em>error.nodeName</em>: The node name that execution failed.</li><li><em>error.message</em>: The error message that execution failed.</li></ol></li><li>Certificate: <br><i>(If there are multiple nodes outputting a certificate before this, it always indicate the nearest one.)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>certificate.commonName</em>: The primary domain or IP address of the certificate.</li><li><em>certificate.subjectAltNames</em>: The domains or IP addresses of the certificate, separated by semicolons.</li><li><em>certificate.notBefore</em>: The effect time of the certificate, formatted in RFC3339.</li><li><em>certificate.notAfter</em>: The expire time of the certificate, formatted in RFC3339.</li><li><em>certificate.hoursLeft</em>: The left hours of the certificate.</li><li><em>certificate.daysLeft</em>: The left days of the certificate.</li><li><em>certificate.validity</em>: The validity of the certificate.</li></ol></li><li>Other: <ol style=\"margin: 0; list-style: '-';\"><li><em>now</em>: The current time on the server, formatted in RFC3339. </li></ol></li></ol><br>Example: <br><em>Your workflow {{ $workflow.name }} has failed on node {{ $error.nodeName }} at {{ $now }}.</em></details>",
"workflow_node.notify.form.template.guide": "<details><summary>The content using the \"Mustache\" syntax (double curly braces) and preceded by \"$\" in the subject or message are text interpolations. They will be replaced by the actual values. </summary><br>Supported text interpolations: <ol style=\"list-style: disc;\"><li>Workflow: <ol style=\"margin: 0; list-style: '-';\"><li><em>workflow.id</em>: The ID of the workflow.</li><li><em>workflow.name</em>: The name of the workflow.</li><li><em>workflow.description</em>: The description of the workflow.</li><li><em>run.id</em>: The ID of the workflow run.</li></ol></li><li>Error: <br><i>(If there are multiple nodes that have failed before this, it always indicate the nearest one.)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>error.nodeId</em>: The node ID that execution failed.</li><li><em>error.nodeName</em>: The node name that execution failed.</li><li><em>error.message</em>: The error message that execution failed.</li></ol></li><li>Certificate: <br><i>(If there are multiple nodes outputting a certificate before this, it always indicate the nearest one.)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>certificate.commonName</em>: The primary domain or IP address of the certificate.</li><li><em>certificate.subjectAltNames</em>: The domains or IP addresses of the certificate, separated by semicolons.</li><li><em>certificate.notBefore</em>: The effect time of the certificate, formatted in RFC3339.</li><li><em>certificate.notAfter</em>: The expire time of the certificate, formatted in RFC3339.</li><li><em>certificate.hoursLeft</em>: The left hours of the certificate.</li><li><em>certificate.daysLeft</em>: The left days of the certificate.</li><li><em>certificate.validity</em>: The validity of the certificate.</li></ol></li><li>Other: <ol style=\"margin: 0; list-style: '-';\"><li><em>now</em>: The current time on the server, formatted in RFC3339. </li></ol></li></ol><br>Example: <br><em>Your workflow {{ $workflow.name }} has failed on node {{ $error.nodeName }} at {{ $now }}.</em></details>",
"workflow_node.notify.form.provider.label": "Notification channel",
"workflow_node.notify.form.provider.placeholder": "Please select notification channel",
"workflow_node.notify.form.provider.search.placeholder": "Search notification channel ...",
@@ -1277,7 +1277,7 @@
"workflow_node.notify.form.subject.placeholder": "请输入通知主题",
"workflow_node.notify.form.message.label": "通知内容",
"workflow_node.notify.form.message.placeholder": "请输入通知内容",
"workflow_node.notify.form.template.guide": "<details><summary>通知主题或内容中使用「Mustache」语法(即双大括号)包裹、并以「$」符号开头的文本会被视为模板插值,将在推送时被替换为实际值。</summary><br>支持的模板插值:<ol style=\"list-style: disc;\"><li>工作流相关:<ol style=\"margin: 0; list-style: '-';\"><li><em>workflow.id</em>:工作流 ID。</li><li><em>workflow.name</em>:工作流名称。</li><li><em>run.id</em>:运行 ID。</li></ol></li><li>异常相关:<br><i>(如果在此之前有多个执行失败的节点,始终表示最近的一个。)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>error.nodeId</em>:执行失败时的节点 ID。</li><li><em>error.nodeName</em>:执行失败时的节点名称。</li><li><em>error.message</em>:执行失败时的错误信息。</li></ol></li><li>证书相关:<br><i>(如果在此之前有多个输出证书的节点,始终表示最近的一个。)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>certificate.commonName</em>:证书主域名或 IP。</li><li><em>certificate.subjectAltNames</em>:证书多域名或 IP,以半角分号隔开。</li><li><em>certificate.notBefore</em>:证书生效时间,以 RFC3339 格式化。</li><li><em>certificate.notAfter</em>:证书过期时间,以 RFC3339 格式化。</li><li><em>certificate.hoursLeft</em>:证书剩余小时数。</li><li><em>certificate.daysLeft</em>:证书剩余天数。</li><li><em>certificate.validity</em>:证书是否有效。</li></ol></li><li>其他:<ol style=\"margin: 0; list-style: '-';\"><li><em>now</em>:服务器当前时间,以 RFC3339 格式化。</li></ol></li></ol><br>示例:<br><em>Your workflow {{ $workflow.name }} has failed on node {{ $error.nodeName }} at {{ $now }}.</em></details>",
"workflow_node.notify.form.template.guide": "<details><summary>通知主题或内容中使用「Mustache」语法(即双大括号)包裹、并以「$」符号开头的文本会被视为模板插值,将在推送时被替换为实际值。</summary><br>支持的模板插值:<ol style=\"list-style: disc;\"><li>工作流相关:<ol style=\"margin: 0; list-style: '-';\"><li><em>workflow.id</em>:工作流 ID。</li><li><em>workflow.name</em>:工作流名称。</li><li><em>workflow.description</em>:工作流描述。</li><li><em>run.id</em>:运行 ID。</li></ol></li><li>异常相关:<br><i>(如果在此之前有多个执行失败的节点,始终表示最近的一个。)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>error.nodeId</em>:执行失败时的节点 ID。</li><li><em>error.nodeName</em>:执行失败时的节点名称。</li><li><em>error.message</em>:执行失败时的错误信息。</li></ol></li><li>证书相关:<br><i>(如果在此之前有多个输出证书的节点,始终表示最近的一个。)</i><ol style=\"margin: 0; list-style: '-';\"><li><em>certificate.commonName</em>:证书主域名或 IP。</li><li><em>certificate.subjectAltNames</em>:证书多域名或 IP,以半角分号隔开。</li><li><em>certificate.notBefore</em>:证书生效时间,以 RFC3339 格式化。</li><li><em>certificate.notAfter</em>:证书过期时间,以 RFC3339 格式化。</li><li><em>certificate.hoursLeft</em>:证书剩余小时数。</li><li><em>certificate.daysLeft</em>:证书剩余天数。</li><li><em>certificate.validity</em>:证书是否有效。</li></ol></li><li>其他:<ol style=\"margin: 0; list-style: '-';\"><li><em>now</em>:服务器当前时间,以 RFC3339 格式化。</li></ol></li></ol><br>示例:<br><em>Your workflow {{ $workflow.name }} has failed on node {{ $error.nodeName }} at {{ $now }}.</em></details>",
"workflow_node.notify.form.provider.label": "通知渠道",
"workflow_node.notify.form.provider.placeholder": "请选择通知渠道",
"workflow_node.notify.form.provider.search.placeholder": "搜索通知渠道……",