Skip to content

Commit 8e8cd79

Browse files
committed
Unify script loading
1 parent dec738f commit 8e8cd79

2 files changed

Lines changed: 7 additions & 18 deletions

File tree

backend/redis/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// KEYS[5] - active-instance-execution key
1616
// KEYS[6] - instances-by-creation key
1717
// ARGV[1] - instance segment
18-
var deleteCmd = redis.NewScript(
18+
var deleteInstanceCmd = redis.NewScript(
1919
`redis.call("DEL", KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5])
2020
return redis.call("ZREM", KEYS[6], ARGV[1])`)
2121

@@ -24,7 +24,7 @@ var deleteCmd = redis.NewScript(
2424
//
2525
// Note: might want to revisit this in the future if we want to support removing hung instances.
2626
func (rb *redisBackend) deleteInstance(ctx context.Context, instance *core.WorkflowInstance) error {
27-
if err := deleteCmd.Run(ctx, rb.rdb, []string{
27+
if err := deleteInstanceCmd.Run(ctx, rb.rdb, []string{
2828
rb.keys.instanceKey(instance),
2929
rb.keys.pendingEventsKey(instance),
3030
rb.keys.historyKey(instance),

backend/redis/redis.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,15 @@ func NewRedisBackend(client redis.UniversalClient, opts ...RedisBackendOption) (
6363
activityQueue: activityQueue,
6464
}
6565

66-
// Preload scripts here.
67-
cmds := map[string]*redis.StringCmd{
68-
"deleteInstanceCmd": deleteCmd.Load(ctx, rb.rdb),
69-
}
70-
for name, cmd := range cmds {
71-
// fmt.Println(name, cmd.Val())
72-
73-
if cmd.Err() != nil {
74-
return nil, fmt.Errorf("loading redis script: %v %w", name, cmd.Err())
75-
}
76-
}
77-
7866
// Load all Lua scripts
7967
cmdMapping := map[string]**redis.Script{
80-
"create_workflow_instance.lua": &createWorkflowInstanceCmd,
81-
"complete_workflow_task.lua": &completeWorkflowTaskCmd,
68+
"cancel_workflow_instance.lua": &cancelWorkflowInstanceCmd,
8269
"complete_activity_task.lua": &completeActivityTaskCmd,
83-
"schedule_future_events.lua": &futureEventsCmd,
70+
"complete_workflow_task.lua": &completeWorkflowTaskCmd,
71+
"create_workflow_instance.lua": &createWorkflowInstanceCmd,
72+
"delete_instance.lua": &deleteInstanceCmd,
8473
"expire_workflow_instance.lua": &expireWorkflowInstanceCmd,
85-
"cancel_workflow_instance.lua": &cancelWorkflowInstanceCmd,
74+
"schedule_future_events.lua": &futureEventsCmd,
8675
"signal_workflow.lua": &signalWorkflowCmd,
8776
}
8877

0 commit comments

Comments
 (0)