Class: Chasqui::MultiBroker

Inherits:
Broker
  • Object
show all
Defined in:
lib/chasqui/multi_broker.rb

Constant Summary

Constants inherited from Broker

Broker::ShutdownSignals

Instance Attribute Summary

Attributes inherited from Broker

#config, #redis, #redis_namespace

Instance Method Summary collapse

Methods inherited from Broker

#initialize, #start, start

Constructor Details

This class inherits a constructor from Chasqui::Broker

Instance Method Details

#build_job(queue, event) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chasqui/multi_broker.rb', line 27

def build_job(queue, event)
  {
    class: "Chasqui::#{Chasqui.subscriber_class_name(queue)}",
    args: [event],
    queue: 'my-queue',
    jid: SecureRandom.hex(12),
    created_at: (event['created_at'] || Time.now).to_f,
    enqueued_at: Time.now.to_f,
    retry: !!event['retry']
  }.to_json
end

#forward_eventObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/chasqui/multi_broker.rb', line 5

def forward_event
  event = receive or return
  subscriptions = subscriptions_for(event)

  redis.multi do
    subscriptions.each do |subscription_id|
      dispatch event, subscription_id
    end
    redis.rpop(in_progress_queue)
  end

  logger.info "processed event: #{event['event']}, on channel: #{event['channel']}"
end

#in_progress_queueObject



19
20
21
# File 'lib/chasqui/multi_broker.rb', line 19

def in_progress_queue
  with_namespace inbox, 'in_progress'
end

#inbox_queueObject



23
24
25
# File 'lib/chasqui/multi_broker.rb', line 23

def inbox_queue
  with_namespace inbox
end