active_event 0.5.0.rc3 → 0.5.0.rc4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_event/event_source_server.rb +58 -5
- data/lib/active_event/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: d695d82e04ff4395d4ed6ed08e40315f63b90722
|
4
|
+
data.tar.gz: 05043c74ef8487177bbb09848a2a13cb9ad69b87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f183b8a4e89b5a32ec86a0764a75d83d945756fdfec065554bd9df51489372204f799292dc134136abf5fadc56c74cd3b87c07fd6dfe3f466ed1063eed728d76
|
7
|
+
data.tar.gz: 636526f08010a506cda3e64155710ab0c9109086cc4d736f2feb37a0bf4a8d1aa6003db56b314f3af8f8cf6e4cb9e62024f1dca1c73b4f3048e18014ce744aa8
|
@@ -1,8 +1,61 @@
|
|
1
|
+
require 'singleton'
|
1
2
|
require 'bunny'
|
3
|
+
|
2
4
|
module ActiveEvent
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
class EventSourceServer
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def self.after_event_projection(event_id, projection, &block)
|
9
|
+
instance.after_event_projection(event_id, projection, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def after_event_projection(event_id, projection)
|
13
|
+
mutex.synchronize do
|
14
|
+
projection_status = status[projection]
|
15
|
+
if projection_status.event_id < event_id
|
16
|
+
cv = ConditionVariable.new
|
17
|
+
begin
|
18
|
+
projection_status.waiters[event_id] << cv
|
19
|
+
cv.wait(mutex)
|
20
|
+
ensure
|
21
|
+
projection_status.waiters[event_id].delete cv
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
class Status
|
31
|
+
attr_accessor :event_id, :waiters, :error, :backtrace
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
self.event_id = 0
|
35
|
+
self.waiters = Hash.new { |h,k| h[k] = [] }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_accessor :mutex # synchronize access to status
|
40
|
+
attr_accessor :status # status of all projections received so far
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
self.mutex = Mutex.new
|
44
|
+
self.status = Hash.new { |h,k| h[k] = Status.new }
|
45
|
+
event_connection.start
|
46
|
+
event_queue.subscribe do |delivery_info, properties, body|
|
47
|
+
process_projection JSON.parse(body).symbolize_keys!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def process_projection(data)
|
52
|
+
mutex.synchronize do
|
53
|
+
projection_status = status[data[:projection]]
|
54
|
+
projection_status.event_id = data[:event]
|
55
|
+
projection_status.error = data[:error] if data.key? :error
|
56
|
+
projection_status.backtrace = data[:backtrace] if data.key? :backtrace
|
57
|
+
projection_status.waiters.delete(data[:event]).to_a.each { |cv| cv.signal }
|
58
|
+
end
|
6
59
|
end
|
7
60
|
|
8
61
|
def event_queue
|
@@ -18,7 +71,7 @@ module ActiveEvent
|
|
18
71
|
end
|
19
72
|
|
20
73
|
def event_exchange
|
21
|
-
|
74
|
+
@@event_exchange ||= event_channel.fanout "server_side_#{options[:event_exchange]}"
|
22
75
|
end
|
23
76
|
|
24
77
|
def default_options
|
@@ -52,4 +105,4 @@ module ActiveEvent
|
|
52
105
|
|
53
106
|
attr_writer :options
|
54
107
|
end
|
55
|
-
end
|
108
|
+
end
|
data/lib/active_event/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0.
|
4
|
+
version: 0.5.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HicknHack Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|