Chore: Refactor round robin logic (#1015)
Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
module Constants::RedisKeys
|
||||
ROUND_ROBIN_AGENTS = 'ROUND_ROBIN_AGENTS:%{inbox_id}'.freeze
|
||||
end
|
||||
@@ -16,9 +16,9 @@ module OnlineStatusTracker
|
||||
def self.presence_key(account_id, type)
|
||||
case type
|
||||
when 'Contact'
|
||||
Redis::Alfred::ONLINE_PRESENCE_CONTACTS % account_id
|
||||
format(::Redis::Alfred::ONLINE_PRESENCE_CONTACTS, account_id: account_id)
|
||||
else
|
||||
Redis::Alfred::ONLINE_PRESENCE_USERS % account_id
|
||||
format(::Redis::Alfred::ONLINE_PRESENCE_USERS, account_id: account_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ module OnlineStatusTracker
|
||||
end
|
||||
|
||||
def self.status_key(account_id)
|
||||
Redis::Alfred::ONLINE_STATUS % account_id
|
||||
format(::Redis::Alfred::ONLINE_STATUS, account_id: account_id)
|
||||
end
|
||||
|
||||
def self.get_available_contacts(account_id)
|
||||
|
||||
@@ -1,43 +1,52 @@
|
||||
module Redis::Alfred
|
||||
CONVERSATION_MAILER_KEY = 'CONVERSATION::%d'.freeze
|
||||
|
||||
# hash containing user_id key and status as value ONLINE_STATUS::%accountid
|
||||
ONLINE_STATUS = 'ONLINE_STATUS::%s'.freeze
|
||||
# sorted set storing online presense of account contacts : ONLINE_PRESENCE::%accountid::CONTACTS
|
||||
ONLINE_PRESENCE_CONTACTS = 'ONLINE_PRESENCE::%s::CONTACTS'.freeze
|
||||
# sorted set storing online presense of account users : ONLINE_PRESENCE::%accountid::USERS
|
||||
ONLINE_PRESENCE_USERS = 'ONLINE_PRESENCE::%s::USERS'.freeze
|
||||
include Redis::RedisKeys
|
||||
|
||||
class << self
|
||||
def rpoplpush(source, destination)
|
||||
$alfred.rpoplpush(source, destination)
|
||||
end
|
||||
# key operations
|
||||
|
||||
def lpush(key, value)
|
||||
$alfred.lpush(key, value)
|
||||
end
|
||||
|
||||
def delete(key)
|
||||
$alfred.del(key)
|
||||
end
|
||||
|
||||
def lrem(key, value, count = 0)
|
||||
$alfred.lrem(key, count, value)
|
||||
def set(key, value)
|
||||
$alfred.set(key, value)
|
||||
end
|
||||
|
||||
def setex(key, value, expiry = 1.day)
|
||||
$alfred.setex(key, expiry, value)
|
||||
end
|
||||
|
||||
def set(key, value)
|
||||
$alfred.set(key, value)
|
||||
end
|
||||
|
||||
def get(key)
|
||||
$alfred.get(key)
|
||||
end
|
||||
|
||||
# hash operation
|
||||
def delete(key)
|
||||
$alfred.del(key)
|
||||
end
|
||||
|
||||
# list operations
|
||||
|
||||
def llen(key)
|
||||
$alfred.llen(key)
|
||||
end
|
||||
|
||||
def lrange(key, start_index = 0, end_index = -1)
|
||||
$alfred.lrange(key, start_index, end_index)
|
||||
end
|
||||
|
||||
def rpop(key)
|
||||
$alfred.rpop(key)
|
||||
end
|
||||
|
||||
def lpush(key, values)
|
||||
$alfred.lpush(key, values)
|
||||
end
|
||||
|
||||
def rpoplpush(source, destination)
|
||||
$alfred.rpoplpush(source, destination)
|
||||
end
|
||||
|
||||
def lrem(key, value, count = 0)
|
||||
$alfred.lrem(key, count, value)
|
||||
end
|
||||
|
||||
# hash operations
|
||||
|
||||
# add a key value to redis hash
|
||||
def hset(key, field, value)
|
||||
@@ -54,7 +63,7 @@ module Redis::Alfred
|
||||
$alfred.hmget(key, *fields)
|
||||
end
|
||||
|
||||
# sorted set functions
|
||||
# sorted set operations
|
||||
|
||||
# add score and value for a key
|
||||
def zadd(key, score, value)
|
||||
|
||||
13
lib/redis/redis_keys.rb
Normal file
13
lib/redis/redis_keys.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Redis::RedisKeys
|
||||
ROUND_ROBIN_AGENTS = 'ROUND_ROBIN_AGENTS:%<inbox_id>d'.freeze
|
||||
|
||||
CONVERSATION_MAILER_KEY = 'CONVERSATION::%<conversation_id>d'.freeze
|
||||
|
||||
## Online Status Keys
|
||||
# hash containing user_id key and status as value
|
||||
ONLINE_STATUS = 'ONLINE_STATUS::%<account_id>d'.freeze
|
||||
# sorted set storing online presense of account contacts
|
||||
ONLINE_PRESENCE_CONTACTS = 'ONLINE_PRESENCE::%<account_id>d::CONTACTS'.freeze
|
||||
# sorted set storing online presense of account users
|
||||
ONLINE_PRESENCE_USERS = 'ONLINE_PRESENCE::%<account_id>d::USERS'.freeze
|
||||
end
|
||||
Reference in New Issue
Block a user