metacosm 0.2.12 → 0.2.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dc2f64e388c19864b4913a01eeb821f6016fdde
4
- data.tar.gz: 0e3f337465c42548784342fde5260f93b14c8808
3
+ metadata.gz: f78fea361e727ab756d606811ca59e1f52a5b1e5
4
+ data.tar.gz: b6539a027a2cf2bac9270b3c60b8a3246b35c228
5
5
  SHA512:
6
- metadata.gz: 28c5f71234421d6fc5c1ac19161dcf8f8b149e30b771c58168becdb2c9c2888d56cd31d372b46f1e8f8566f55ea763a886b7dffa2af030b402790bd8becf186f
7
- data.tar.gz: 1bcad03a5914c8cb0b47c5ddb7bf5a219dc7433e59b246b74a7b14844dc4fb755157701ce0b14950eefe1965c59ad67794fc5664d4313296d0a0c9f46621fb49
6
+ metadata.gz: c34e16473d596582f095fa4785cb01e0de4f7a3436eae237b582ed504a1c9555950892afe4a643fbc85716cbb473d40b5d149778d0acbc4e2d7cc1f22f1a6ee4
7
+ data.tar.gz: 15c5c5734f37cd1a1c088822027127dedc861381a25d3934fc6d622905fdec38666c12c299eb3acdbf9e3cc23f7be77430ab6867502bf4cc1bf4c2e2269ec107
@@ -0,0 +1,48 @@
1
+ module Metacosm
2
+ class RemoteSimulation < Simulation
3
+ def initialize
4
+ setup_connection
5
+ end
6
+
7
+ def redis_connection
8
+ Redis.new
9
+ end
10
+
11
+ def fire(command)
12
+ command_dto = command.attrs.merge(handler_module: command.handler_module_name, handler_class_name: command.handler_class_name)
13
+ redis = redis_connection
14
+ redis.publish(:socius_command_queue, Marshal.dump(command_dto))
15
+ end
16
+
17
+ def setup_connection
18
+ @remote_listener_thread = Thread.new do
19
+ begin
20
+ redis = redis_connection
21
+ redis.subscribe(:socius_event_stream) do |on|
22
+ on.subscribe do |channel, subscriptions|
23
+ puts "Subscribed to remote simulation event stream ##{channel} (#{subscriptions} subscriptions)"
24
+ end
25
+
26
+ on.message do |channel, message|
27
+ event = Marshal.load(message)
28
+ listener_module_name = event.delete(:listener_module)
29
+ listener_class_name = event.delete(:listener_class_name)
30
+ module_name = listener_module_name
31
+ module_name = "Object" if module_name.empty?
32
+ listener = (module_name.constantize).const_get(listener_class_name).new(self)
33
+ listener.receive(event)
34
+ end
35
+
36
+ on.unsubscribe do |channel, subscriptions|
37
+ puts "Unsubscribed from remote simulation event stream ##{channel} (#{subscriptions} subscriptions)"
38
+ end
39
+ end
40
+ rescue Redis::BaseConnectionError => error
41
+ puts "#{error}, retrying in 1s"
42
+ sleep 1
43
+ retry
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -82,11 +82,6 @@ module Metacosm
82
82
  end
83
83
  end
84
84
 
85
- # TODO lift this stuff from socius
86
- # def push_commands_to(channel:)
87
- # @command_push_channel = channel
88
- # end
89
-
90
85
  def subscribe_for_commands(channel:)
91
86
  p [ :subscribe_to_command_channel, channel: channel ]
92
87
  redis = Redis.new
@@ -1,4 +1,4 @@
1
1
  module Metacosm
2
2
  # metacosm version
3
- VERSION = "0.2.12"
3
+ VERSION = "0.2.13"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metacosm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: passive_record
@@ -163,7 +163,7 @@ files:
163
163
  - gemspec.yml
164
164
  - lib/metacosm.rb
165
165
  - lib/metacosm/model.rb
166
- - lib/metacosm/redis_simulation.rb
166
+ - lib/metacosm/remote_simulation.rb
167
167
  - lib/metacosm/simulation.rb
168
168
  - lib/metacosm/support/spec_harness.rb
169
169
  - lib/metacosm/support/test_harness.rb
@@ -1,6 +0,0 @@
1
- module Metacosm
2
- # class RedisSimulation < Simulation
3
- # # need to override remote command/event queue logic
4
- # # and use redis pub/sub instead...
5
- # end
6
- end