<commit_before>local broker_id = ARGV[1]
local now = ARGV[2]
local periodic_tasks_hash = ARGV[3]
local periodic_tasks_queue = ARGV[4]
-- tasks to register starting at ARGV[5]


local function contains(t, e)
  return t[e]
end


local old_task_names = redis.call('hkeys', periodic_tasks_hash)
local new_task_names = {}

for i=5, #ARGV do
    local task_json = ARGV[i]
    local task = cjson.decode(task_json)
    local next_event_time = now + task["periodicity"]
    new_task_names[task["name"]] = true

    if redis.call('hexists', periodic_tasks_hash, task["name"]) == 0 then
        redis.call('zadd', periodic_tasks_queue, next_event_time, task["name"])
    end
    redis.call('hset', periodic_tasks_hash, task["name"], task_json)
end


for i=1, #old_task_names do
    local old_task_name = old_task_names[i]
    if not contains(new_task_names, old_task_name) then
        redis.call('hdel', periodic_tasks_hash, old_task_name)
    end
end
<commit_msg>Reset periodic task score when periodicity is changed<commit_after>local broker_id = ARGV[1]
local now = ARGV[2]
local periodic_tasks_hash = ARGV[3]
local periodic_tasks_queue = ARGV[4]
-- tasks to register starting at ARGV[5]


local function contains(t, e)
  return t[e]
end


local old_task_names = redis.call('hkeys', periodic_tasks_hash)
local new_task_names = {}

for i=5, #ARGV do
    local task_json = ARGV[i]
    local task = cjson.decode(task_json)
    local next_event_time = now + task["periodicity"]
    new_task_names[task["name"]] = true

    if redis.call('hexists', periodic_tasks_hash, task["name"]) == 0 then
        -- the periodic task is new, add it to the queue
        redis.call('zadd', periodic_tasks_queue, next_event_time, task["name"])
    else
        local existing_task_json = redis.call('hget', periodic_tasks_hash, task["name"])
        local existing_task = cjson.decode(existing_task_json)
        if existing_task["periodicity"] ~= task["periodicity"] then
            -- the periodic task already existed but the periodicity changed
            -- so it is reset
            redis.call('zadd', periodic_tasks_queue, next_event_time, task["name"])
        end
    end

    -- unconditionnally override the task in the hash
    redis.call('hset', periodic_tasks_hash, task["name"], task_json)
end


for i=1, #old_task_names do
    local old_task_name = old_task_names[i]
    if not contains(new_task_names, old_task_name) then
        redis.call('hdel', periodic_tasks_hash, old_task_name)
        redis.call('zrem', periodic_tasks_queue, old_task_name)
    end
end

{'fraction_non_alphanumeric': 0.10719874804381847, 'fraction_numerical': 0.006259780907668232, 'mean_word_length': 4.023575638506876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2978499', 'n_tokens_mistral': 877, 'n_tokens_neox': 854, 'n_words': 218}