@@ -60,6 +60,7 @@ class AnyCableSubscriptions < GraphQL::Subscriptions
6060 FINGERPRINTS_PREFIX = "fingerprints:" # ZSET: To get fingerprints by topic
6161 SUBSCRIPTIONS_PREFIX = "subscriptions:" # SET: To get subscriptions by fingerprint
6262 CHANNEL_PREFIX = "channel:" # SET: Auxiliary structure for whole channel's subscriptions cleanup
63+ EXECUTOR_METHOD_NAME = "execute_synchronically" # method, who execute the main logic
6364
6465 # @param serializer [<#dump(obj), #load(string)] Used for serializing messages before handing them to `.broadcast(msg)`
6566 def initialize ( serializer : Serialize , **rest )
@@ -73,6 +74,13 @@ def execute_all(event, object)
7374 fingerprints = redis . zrange ( redis_key ( FINGERPRINTS_PREFIX ) + event . topic , 0 , -1 )
7475 return if fingerprints . empty?
7576
77+ perform ( event , object )
78+ end
79+
80+ def execute_synchronically ( event , object )
81+ fingerprints = redis . zrange ( redis_key ( FINGERPRINTS_PREFIX ) + event . topic , 0 , -1 )
82+ return if fingerprints . empty?
83+
7684 fingerprint_subscription_ids = Hash [ fingerprints . zip (
7785 redis . pipelined do |pipeline |
7886 fingerprints . map do |fingerprint |
@@ -243,6 +251,24 @@ def fetch_channel_istate(channel)
243251 def redis_key ( prefix )
244252 "#{ config . redis_prefix } -#{ prefix } "
245253 end
254+
255+ def executor_class_job
256+ custom_class = config . async_broadcasting [ "class" ]
257+
258+ return Adapters ::BaseJob unless custom_class
259+
260+ Object . const_get ( config . async_broadcasting [ "class" ] )
261+ end
262+
263+ def perform ( event , object )
264+ unless config . use_async_broadcasting
265+ return public_send ( EXECUTOR_METHOD_NAME , event , object )
266+ end
267+
268+ args = [ Marshal . dump ( self ) , EXECUTOR_METHOD_NAME , Marshal . dump ( event ) , Marshal . dump ( object ) ]
269+
270+ executor_class_job . perform_later ( *args )
271+ end
246272 end
247273 end
248274end
0 commit comments