dferrazm / active_job_lock

An ActiveJob plugin; adds locking, with optional timeout/deadlock handling.
MIT License
0 stars 4 forks source link

Redis is polluted when GlobalId is used to pass arguments #3

Open loveapoex opened 6 years ago

loveapoex commented 6 years ago

Documentation taken from here

image

How to recreate

class UpdateUserJob < ActiveJob::Base
  include ActiveJobLock::Core

  lock loner: true

  def perform(user)
    user.update_something_important
  end
end

Enqueue Job:

user = User.first

puts user.to_s
=> "#<User:0x00007f9101f10c90>"

UpdateUserJob.perform_later(user)

Check locks:

redis-cli KEYS "loner:lock:UpdateUserJob:*"
loner:lock:UpdateUserJob:#<User:0x00007f9101f10c90>

Wait for job to be processed by workers... Check locks:

redis-cli KEYS "loner:lock:UpdateUserJob:*"
loner:lock:UpdateUserJob:#<User:0x00007f9101f10c90>

Problem

redis_loner_lock_key generates different keys when called from enqueue and perform when relying on GlobalId to pass ActiveRecord objects as parameters, which causes Redis to be polluted.

Startouf commented 5 years ago

There seem to be another redis-based gem out there that already deals with GlobalId https://github.com/erickrause/activejob-locks