From f49871cc1c0e18e14592f0de129f6cd4b7da40a9 Mon Sep 17 00:00:00 2001 From: Achim Rohn Date: Mon, 6 Apr 2026 18:34:31 +0200 Subject: [PATCH] Add random string to the workflow id --- strings.go | 10 ++++++++++ workflow/workflow.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/strings.go b/strings.go index 1a70fa3..cc79e43 100644 --- a/strings.go +++ b/strings.go @@ -3,6 +3,7 @@ package ersteller import ( "bytes" "fmt" + mathRand "math/rand" "regexp" "strings" "text/template" @@ -35,3 +36,12 @@ func InlineTemplate(templateString string, data any) string { } return buf.String() } + +func RandomString(n int) string { + const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + b := make([]byte, n) + for i := range b { + b[i] = letters[int(mathRand.Int63()%int64(len(letters)))] + } + return string(b) +} diff --git a/workflow/workflow.go b/workflow/workflow.go index 0734465..9de266e 100644 --- a/workflow/workflow.go +++ b/workflow/workflow.go @@ -111,7 +111,7 @@ func (w *Workflow) Execute(ctx context.Context, payload map[string]any) error { func (w *Workflow) GenerateId() string { now := time.Now() - return w.Identifier + "_" + now.Format("20060102150405") + return w.Identifier + "_" + now.Format("20060102150405") + "_" + ersteller.RandomString(5) } func NewCronTrigger(ctx context.Context, workflow *Workflow, d time.Duration) {