wampus 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wampus/backends/redis.rb +54 -52
- data/lib/wampus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24dd3f5e9601271d25b1ba20bb489dcdc9d9282c
|
4
|
+
data.tar.gz: 8af28ecdb9b6db135c99082f74b40e918be2e5c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e475438bf58140e41989c659525af5af26a3b0305aafec3cd5af6cc10068eb179a374a847c0768dc3b5b59d9832511c18fd1822187768dfe3f4a7092de52cdfe
|
7
|
+
data.tar.gz: 033812f181b04eb2dfd3295fd68f98917965be1b5718bceb4ad058fdaefc6d16316747f2bbf174f5dacf391b156f9fcf3bb324e09963a6bbe2c8e2454893345e
|
@@ -6,45 +6,47 @@ module Wampus
|
|
6
6
|
module Redis
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
+
attr_reader :redis_config
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
@redis_config = redis_defaults.dup
|
13
|
+
super(*args) if defined? super
|
14
|
+
end
|
15
|
+
|
9
16
|
included do
|
10
|
-
class_attribute :
|
11
|
-
self.
|
12
|
-
:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
:namespace => ''
|
20
|
-
}
|
17
|
+
class_attribute :redis_defaults
|
18
|
+
self.redis_defaults = {
|
19
|
+
:host => 'localhost',
|
20
|
+
:port => 6379,
|
21
|
+
:database => 0,
|
22
|
+
:password => nil,
|
23
|
+
:gc => 60,
|
24
|
+
:lock_timeout => 120,
|
25
|
+
:namespace => ''
|
21
26
|
}
|
22
|
-
class_attribute :backend_redis_config
|
23
|
-
self.backend_config = {:redis => {}}
|
24
27
|
end
|
25
28
|
|
26
29
|
module ClassMethods
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
+
def configure_redis(options = {})
|
31
|
+
redis_config = redis_defaults.merge options
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def
|
34
|
-
@events_namespace =
|
35
|
+
def connect_to_redis
|
36
|
+
@events_namespace = redis_config[:namespace] + ':events'
|
35
37
|
|
36
38
|
@completed_events = []
|
37
39
|
|
38
|
-
@redis = ::Redis.new(:host =>
|
39
|
-
@subscriber = ::Redis.new(:host =>
|
40
|
+
@redis = ::Redis.new(:host => redis_config[:host], :port => redis_config[:port])
|
41
|
+
@subscriber = ::Redis.new(:host => redis_config[:host], :port => redis_config[:port])
|
40
42
|
|
41
|
-
if
|
42
|
-
@redis.auth(
|
43
|
-
@subscriber.auth(
|
43
|
+
if redis_config[:password]
|
44
|
+
@redis.auth(redis_config[:password])
|
45
|
+
@subscriber.auth(redis_config[:password])
|
44
46
|
end
|
45
47
|
|
46
|
-
@redis.select(
|
47
|
-
@subscriber.select(
|
48
|
+
@redis.select(redis_config[:database])
|
49
|
+
@subscriber.select(redis_config[:database])
|
48
50
|
|
49
51
|
Thread.new do
|
50
52
|
@subscriber.subscribe(@events_namespace) do |on|
|
@@ -56,45 +58,45 @@ module Wampus
|
|
56
58
|
|
57
59
|
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
61
|
+
def create_event(connection, topic, payload, excluded, included)
|
62
|
+
create_event_on_redis(connection.id, topic.uri, payload, excluded, included)
|
63
|
+
end
|
62
64
|
|
63
|
-
|
65
|
+
private
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
def create_event_on_redis(connection_id, topic_uri, payload, excluded, included)
|
68
|
+
@redis.publish @events_namespace, [SecureRandom.uuid, connection_id, topic_uri, payload, excluded, included].to_json
|
69
|
+
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
71
|
+
def subscribe_to_events
|
72
|
+
Thread.new do
|
73
|
+
@subscriber.subscribe(@events_ns) do |on|
|
74
|
+
on.message do |channel, message|
|
75
|
+
handle_message_from_redis(message)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
end
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
def handle_message_from_redis(message)
|
82
|
+
begin
|
83
|
+
id, connection_id, uri, payload, excluded, included = JSON.parse(message)
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
+
connection = find_connections(:id => connection_id).first
|
86
|
+
topic = topic_for_uri uri
|
85
87
|
|
86
|
-
|
88
|
+
return unless topic
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
90
|
+
topic.subscribers(connection, excluded, included) do |subscribers|
|
91
|
+
subscribers.each do |connection|
|
92
|
+
connection.write event_msg(topic.uri, payload)
|
92
93
|
end
|
93
|
-
rescue => error
|
94
|
-
# TODO Handle Error
|
95
94
|
end
|
95
|
+
rescue => error
|
96
|
+
# TODO Handle Error
|
96
97
|
end
|
97
|
-
|
98
98
|
end
|
99
|
+
|
99
100
|
end
|
100
|
-
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/wampus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wampus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Stack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|