alondra 0.1.0 → 0.1.1
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.
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/alondra.gemspec +1 -0
- data/bin/alondra +45 -0
- data/lib/alondra.rb +13 -6
- data/lib/alondra/version.rb +1 -1
- data/test/models/configuration_test.rb +1 -1
- data/test/models/message_queue_test.rb +22 -22
- metadata +7 -5
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -161,10 +161,10 @@ In the shell execute the generator.
|
|
161
161
|
$ rails g alondra install
|
162
162
|
</pre>
|
163
163
|
|
164
|
-
To run the Alondra server, just call the
|
164
|
+
To run the Alondra server, just call the provided executable in your project directory
|
165
165
|
|
166
166
|
<pre>
|
167
|
-
$
|
167
|
+
$ bundle exec alondra
|
168
168
|
</pre>
|
169
169
|
|
170
170
|
In development mode you can also run the Alondra server in its own thread.
|
data/alondra.gemspec
CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.version = Alondra::VERSION
|
9
9
|
s.authors = ['Alberto F. Capel', 'Ryan LeCompte']
|
10
10
|
|
11
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
12
|
s.files = `git ls-files`.split("\n")
|
12
13
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
14
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/bin/alondra
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
options = {}
|
4
|
+
|
5
|
+
parser = OptionParser.new do |opts|
|
6
|
+
opts.on "-p", "--port PORT", Integer,
|
7
|
+
"Define what port TCP port to bind to (default: 3000)" do |arg|
|
8
|
+
options[:port] = arg
|
9
|
+
end
|
10
|
+
|
11
|
+
opts.on "-a", "--address HOST",
|
12
|
+
"bind to HOST address (default: 0.0.0.0)" do |arg|
|
13
|
+
options[:host] = arg
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on "-s", "--queue-socket PATH", "Socket for IPC communication" do
|
17
|
+
options[:quiet] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on "-e", "--environment ENVIRONMENT",
|
21
|
+
"The environment to run the Rack app on (default: development)" do |arg|
|
22
|
+
ENV['RACK_ENV'] ||= arg
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
parser.banner = "alondra <options>"
|
27
|
+
|
28
|
+
parser.on_tail "-h", "--help", "Show help" do
|
29
|
+
puts parser
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
parser.parse(ARGV)
|
34
|
+
|
35
|
+
ENV['RACK_ENV'] ||= 'development'
|
36
|
+
|
37
|
+
require './config/environment'
|
38
|
+
require 'alondra'
|
39
|
+
|
40
|
+
|
41
|
+
Alondra::Alondra.start_with_options(options)
|
42
|
+
|
43
|
+
puts "Alondra server started at port #{Alondra::Alondra.config.port}"
|
44
|
+
|
45
|
+
sleep
|
data/lib/alondra.rb
CHANGED
@@ -25,9 +25,9 @@ module Alondra
|
|
25
25
|
|
26
26
|
# Setting default configuration values
|
27
27
|
config.port = Rails.env == 'test' ? 12346 : 12345
|
28
|
-
config.host = '
|
28
|
+
config.host = '0.0.0.0'
|
29
29
|
config.queue_socket = 'ipc:///tmp/alondra.ipc'
|
30
|
-
|
30
|
+
|
31
31
|
initializer "configure EM thread pool" do
|
32
32
|
# If we have more threads than db connections we will exhaust the conn pool
|
33
33
|
threadpool_size = ActiveRecord::Base.connection_pool.instance_variable_get :@size
|
@@ -41,15 +41,22 @@ module Alondra
|
|
41
41
|
|
42
42
|
initializer "load listeners" do
|
43
43
|
listeners_dir = File.join(Rails.root, 'app', 'listeners')
|
44
|
-
|
44
|
+
|
45
45
|
Log.info "Loading event listeners in #{listeners_dir}"
|
46
46
|
Dir[File.join(listeners_dir, '*.rb')].each { |file| require_dependency file }
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
config.after_initialize do
|
50
50
|
PushController.send :include, Rails.application.routes.url_helpers
|
51
51
|
end
|
52
52
|
|
53
|
+
def self.start_with_options(options)
|
54
|
+
options.each do |k, v|
|
55
|
+
config.send "#{k}=", v
|
56
|
+
end
|
57
|
+
start_server_in_new_thread!
|
58
|
+
end
|
59
|
+
|
53
60
|
def self.start_server_in_new_thread!
|
54
61
|
Thread.new do
|
55
62
|
start_server!
|
@@ -61,9 +68,9 @@ module Alondra
|
|
61
68
|
MessageQueue.instance.start_listening
|
62
69
|
Server.run
|
63
70
|
end
|
64
|
-
|
71
|
+
|
65
72
|
if EM.reactor_running?
|
66
|
-
EM.schedule(start_server_proc)
|
73
|
+
EM.schedule(start_server_proc)
|
67
74
|
else
|
68
75
|
Log.info "starting EM reactor"
|
69
76
|
EM.run(start_server_proc)
|
data/lib/alondra/version.rb
CHANGED
@@ -9,7 +9,7 @@ module Alondra
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test "it allows to override default values" do
|
12
|
-
assert_equal '
|
12
|
+
assert_equal '0.0.0.0', Alondra.config.host
|
13
13
|
Alondra.config.host = 'www.example.com'
|
14
14
|
assert_equal 'www.example.com', Alondra.config.host
|
15
15
|
end
|
@@ -17,28 +17,28 @@ module Alondra
|
|
17
17
|
MessageQueue.instance.instance_variable_set :@event_router, @original_event_router
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
20
|
+
test "a message pushed asynchronously to the queue is received by the event router" do
|
21
|
+
assert MessageQueueClient.instance.class == AsyncMessageQueueClient
|
22
|
+
|
23
|
+
MessageQueueClient.push @event
|
24
|
+
|
25
|
+
sleep(0.1)
|
26
|
+
|
27
|
+
assert received(@event)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "a message pushed synchronously to the queue is received by the event router" do
|
31
|
+
|
32
|
+
client = MessageQueueClient.sync_instance
|
33
|
+
context = client.send :context
|
34
|
+
assert context.class == ZMQ::Context
|
35
|
+
|
36
|
+
client.send_message(@event)
|
37
|
+
|
38
|
+
sleep(0.1)
|
39
|
+
|
40
|
+
assert received(@event)
|
41
|
+
end
|
42
42
|
|
43
43
|
test "message queue still works when an exception is thrown while processing an event" do
|
44
44
|
3.times do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alondra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: daemons
|
@@ -94,7 +94,8 @@ dependencies:
|
|
94
94
|
version: 0.3.0
|
95
95
|
description: Add real time capabilities to your rails app
|
96
96
|
email:
|
97
|
-
executables:
|
97
|
+
executables:
|
98
|
+
- alondra
|
98
99
|
extensions: []
|
99
100
|
extra_rdoc_files: []
|
100
101
|
files:
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- app/assets/javascripts/vendor/web_socket.js
|
114
115
|
- app/assets/swf/WebSocketMain.swf
|
115
116
|
- app/helpers/alondra_helper.rb
|
117
|
+
- bin/alondra
|
116
118
|
- lib/alondra.rb
|
117
119
|
- lib/alondra/changes_callbacks.rb
|
118
120
|
- lib/alondra/changes_push.rb
|
@@ -230,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
230
232
|
version: '0'
|
231
233
|
segments:
|
232
234
|
- 0
|
233
|
-
hash:
|
235
|
+
hash: -3383866246703754523
|
234
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
237
|
none: false
|
236
238
|
requirements:
|
@@ -239,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
241
|
version: '0'
|
240
242
|
segments:
|
241
243
|
- 0
|
242
|
-
hash:
|
244
|
+
hash: -3383866246703754523
|
243
245
|
requirements: []
|
244
246
|
rubyforge_project:
|
245
247
|
rubygems_version: 1.8.23
|