Module: Insque

Defined in:
lib/insque.rb,
lib/insque/railtie.rb,
lib/insque/version.rb,
lib/generators/insque/initializer_generator.rb

Defined Under Namespace

Modules: Generators Classes: Railtie

Constant Summary collapse

VERSION =
"0.5.2"

Class Method Summary collapse

Class Method Details

.broadcast(message, params = nil, recipient = :any) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/insque.rb', line 40

def self.broadcast message, params = nil, recipient = :any
  keys = []
  case recipient
  when :any
    keys = @redis.smembers '{insque}inboxes'
  when :self
    keys = [@inbox]
  when :slow
    keys = [@slow_inbox]
  else
    keys = recipient.is_a?(Array) ? recipient : [recipient]
  end
  value = { :message => "#{@sender}_#{message}", :params => params, :broadcasted_at => Time.now.utc }
  log "SENDING: #{value.to_json} TO #{keys.to_json}" if @debug
  @redis.multi do |r|
    keys.each {|k| r.lpush k, value.to_json}
  end
end

.debug=(debug) ⇒ Object



6
7
8
# File 'lib/insque.rb', line 6

def self.debug= debug
  @debug = debug
end

.janitor(redis = nil) ⇒ Object



69
70
71
# File 'lib/insque.rb', line 69

def self.janitor redis=nil
  real_janitor @inbox, @processing, (redis || create_redis_connection)
end

.listen(worker_name = '', redis = nil) ⇒ Object



59
60
61
62
63
# File 'lib/insque.rb', line 59

def self.listen worker_name='', redis=nil
  redis ||= create_redis_connection
  redis.sadd '{insque}inboxes', @inbox
  do_listen @inbox, @processing, redis, worker_name
end

.redisObject



14
15
16
# File 'lib/insque.rb', line 14

def self.redis
  @redis
end

.redis=(redis) ⇒ Object



10
11
12
# File 'lib/insque.rb', line 10

def self.redis= redis
  @redis = redis
end

.redis_class=(klass) ⇒ Object



18
19
20
# File 'lib/insque.rb', line 18

def self.redis_class= klass
  @redis_class = klass
end

.redis_configObject



22
23
24
# File 'lib/insque.rb', line 22

def self.redis_config
  @redis_config
end

.redis_config=(redis) ⇒ Object



26
27
28
29
# File 'lib/insque.rb', line 26

def self.redis_config= redis
  @redis_config = redis
  @redis = self.create_redis_connection
end

.sender=(sender) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/insque.rb', line 31

def self.sender= sender
  @sender = sender
  @inbox = "{insque}inbox_#{sender}"
  @processing = "{insque}processing_#{sender}"
  @slow_inbox = "{insque}slow_inbox_#{sender}"
  @slow_processing = "{insque}slow_processing_#{sender}"
  create_send_later_handler
end

.slow_janitor(redis = nil) ⇒ Object



73
74
75
# File 'lib/insque.rb', line 73

def self.slow_janitor redis=nil
  real_janitor @slow_inbox, @slow_processing, (redis || create_redis_connection)
end

.slow_listen(worker_name = '', redis = nil) ⇒ Object



65
66
67
# File 'lib/insque.rb', line 65

def self.slow_listen worker_name='', redis=nil
  do_listen @slow_inbox, @slow_processing, (redis || create_redis_connection), worker_name
end