move rhailib to herolib
This commit is contained in:
46
rhailib/benches/simple_rhai_bench/batch_task.lua
Normal file
46
rhailib/benches/simple_rhai_bench/batch_task.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
-- Minimal Lua script for single task creation (n=1)
|
||||
-- Args: circle_name, rhai_script_content, task_count (optional, defaults to 1)
|
||||
-- Returns: array of task keys for timing
|
||||
|
||||
if #ARGV < 2 then
|
||||
return redis.error_reply("Usage: EVAL script 0 circle_name rhai_script_content [task_count]")
|
||||
end
|
||||
|
||||
local circle_name = ARGV[1]
|
||||
local rhai_script_content = ARGV[2]
|
||||
local task_count = tonumber(ARGV[3]) or 1
|
||||
|
||||
-- Validate task_count
|
||||
if task_count <= 0 or task_count > 10000 then
|
||||
return redis.error_reply("task_count must be a positive integer between 1 and 10000")
|
||||
end
|
||||
|
||||
-- Get current timestamp in Unix seconds (to match worker expectations)
|
||||
local rhai_task_queue = 'rhai_tasks:' .. circle_name
|
||||
local task_keys = {}
|
||||
local current_time = redis.call('TIME')[1]
|
||||
|
||||
-- Create multiple tasks
|
||||
for i = 1, task_count do
|
||||
-- Generate unique task ID
|
||||
local task_id = 'task_' .. redis.call('INCR', 'global_task_counter')
|
||||
local task_details_key = 'rhai_task_details:' .. task_id
|
||||
|
||||
-- Create task details hash with creation timestamp
|
||||
redis.call('HSET', task_details_key,
|
||||
'script', rhai_script_content,
|
||||
'status', 'pending',
|
||||
'createdAt', current_time,
|
||||
'updatedAt', current_time,
|
||||
'task_sequence', tostring(i)
|
||||
)
|
||||
|
||||
-- Queue the task for workers
|
||||
redis.call('LPUSH', rhai_task_queue, task_id)
|
||||
|
||||
-- Add key to return array
|
||||
table.insert(task_keys, task_details_key)
|
||||
end
|
||||
|
||||
-- Return array of task keys for timing analysis
|
||||
return task_keys
|
Reference in New Issue
Block a user