-
Notifications
You must be signed in to change notification settings - Fork 80
Move to Redis lua scripts #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
23815ee
b7fedd1
dec738f
8e8cd79
1678632
06830a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| local payloadHashKey = KEYS[1] | ||
| local pendingEventsKey = KEYS[2] | ||
| local workflowSetKey = KEYS[3] | ||
| local workflowStreamKey = KEYS[4] | ||
|
|
||
| local eventId = ARGV[1] | ||
| local eventData = ARGV[2] | ||
| local payload = ARGV[3] | ||
| local instanceSegment = ARGV[4] | ||
|
|
||
| -- Add event payload | ||
| redis.pcall("HSETNX", payloadHashKey, eventId, payload) | ||
|
|
||
| -- Add event to pending events stream | ||
| redis.call("XADD", pendingEventsKey, "*", "event", eventData) | ||
|
|
||
| -- Queue workflow task | ||
| local added = redis.call("SADD", workflowSetKey, instanceSegment) | ||
| if added == 1 then | ||
| redis.call("XADD", workflowStreamKey, "*", "id", instanceSegment, "data", "") | ||
| end | ||
|
|
||
| return true | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||
| -- Complete an activity task, add the result event to the workflow instance, and enqueue the workflow task | ||||||
| -- KEYS[1] = activity set key | ||||||
| -- KEYS[2] = activity stream key | ||||||
| -- KEYS[3] = pending events stream key | ||||||
| -- KEYS[4] = payload hash key | ||||||
| -- KEYS[5] = workflow queues set key | ||||||
| -- KEYS[6] = workflow set key (for specific queue) | ||||||
| -- KEYS[7] = workflow stream key (for specific queue) | ||||||
| -- ARGV[1] = task id (activity) | ||||||
| -- ARGV[2] = group name (activity group) | ||||||
| -- ARGV[3] = event id | ||||||
| -- ARGV[4] = event data (json, without attributes) | ||||||
| -- ARGV[5] = payload data (json, can be empty) | ||||||
| -- ARGV[6] = workflow queue group name | ||||||
| -- ARGV[7] = workflow instance segment id | ||||||
|
|
||||||
| -- Complete the activity task (from queue/complete.lua) | ||||||
| local task = redis.call("XRANGE", KEYS[2], ARGV[1], ARGV[1]) | ||||||
| if #task == 0 then | ||||||
| return nil | ||||||
| end | ||||||
|
|
||||||
| local id = task[1][2][2] | ||||||
| redis.call("SREM", KEYS[1], id) | ||||||
| redis.call("XACK", KEYS[2], "NOMKSTREAM", ARGV[2], ARGV[1]) | ||||||
|
cschleiden marked this conversation as resolved.
|
||||||
| redis.call("XDEL", KEYS[2], ARGV[1]) | ||||||
|
|
||||||
| -- Add event to pending events stream for workflow instance | ||||||
| redis.call("XADD", KEYS[3], "*", "event", ARGV[4]) | ||||||
|
|
||||||
| -- Store payload if provided (only if not empty) | ||||||
| if ARGV[5] ~= "" then | ||||||
| redis.pcall("HSETNX", KEYS[4], ARGV[3], ARGV[5]) | ||||||
|
||||||
| redis.pcall("HSETNX", KEYS[4], ARGV[3], ARGV[5]) | |
| redis.call("HSETNX", KEYS[4], ARGV[3], ARGV[5]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| local instanceKey = KEYS[1] | ||
| local pendingEventsKey = KEYS[2] | ||
| local historyKey = KEYS[3] | ||
| local payloadKey = KEYS[4] | ||
| local activeInstanceExecutionKey = KEYS[5] | ||
| local instancesByCreationKey = KEYS[6] | ||
|
|
||
| local instanceSegment = ARGV[1] | ||
|
|
||
| -- Delete all instance-related keys | ||
| redis.call("DEL", instanceKey, pendingEventsKey, historyKey, payloadKey, activeInstanceExecutionKey) | ||
|
|
||
| -- Remove instance from sorted set | ||
| return redis.call("ZREM", instancesByCreationKey, instanceSegment) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||
| -- Signal a workflow instance by adding an event to its pending events stream and queuing it | ||||||
| -- | ||||||
| -- KEYS[1] - payload hash key | ||||||
| -- KEYS[2] - pending events stream key | ||||||
| -- KEYS[3] - workflow task set key | ||||||
| -- KEYS[4] - workflow task stream key | ||||||
| -- | ||||||
| -- ARGV[1] - event id | ||||||
| -- ARGV[2] - event data (JSON) | ||||||
| -- ARGV[3] - event payload (JSON) | ||||||
| -- ARGV[4] - instance segment | ||||||
|
|
||||||
| local payloadHashKey = KEYS[1] | ||||||
| local pendingEventsKey = KEYS[2] | ||||||
| local workflowSetKey = KEYS[3] | ||||||
| local workflowStreamKey = KEYS[4] | ||||||
|
|
||||||
| local eventId = ARGV[1] | ||||||
| local eventData = ARGV[2] | ||||||
| local payload = ARGV[3] | ||||||
| local instanceSegment = ARGV[4] | ||||||
|
|
||||||
| -- Add event payload | ||||||
| redis.pcall("HSETNX", payloadHashKey, eventId, payload) | ||||||
|
||||||
| redis.pcall("HSETNX", payloadHashKey, eventId, payload) | |
| redis.call("HSETNX", payloadHashKey, eventId, payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent error handling: Line 12 uses
redis.pcall(which suppresses errors) while lines 15, 18, and 20 useredis.call(which propagates errors). Since payload storage is critical for event processing, useredis.callhere for consistent error propagation.