Open loveapoex opened 6 years ago
Documentation taken from here
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_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.
redis_loner_lock_key
enqueue
perform
There seem to be another redis-based gem out there that already deals with GlobalId https://github.com/erickrause/activejob-locks
Documentation taken from here
How to recreate
Enqueue Job:
Check locks:
Wait for job to be processed by workers... Check locks:
Problem
redis_loner_lock_key
generates different keys when called fromenqueue
andperform
when relying on GlobalId to pass ActiveRecord objects as parameters, which causes Redis to be polluted.