dashing-rails 2.6.1 → 2.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +6 -3
- data/app/controllers/dashing/events_controller.rb +12 -7
- data/app/controllers/dashing/widgets_controller.rb +3 -1
- data/lib/dashing.rb +4 -2
- data/lib/dashing/configuration.rb +1 -1
- data/lib/dashing/railtie.rb +4 -2
- data/lib/dashing/version.rb +1 -1
- data/spec/controllers/dashing/widgets_controller_spec.rb +3 -2
- data/spec/lib/dashing/configuration_spec.rb +2 -1
- data/spec/support/controller_spec_helpers.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06cc63083d02f095ae16feb5e29521f4b448cc97
|
4
|
+
data.tar.gz: bef8bbb5ca30a5ebe0449c3544ace81d8457017a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f940073cb5fe34b9a6b9664f893b57824309fb1a83c88a247d6e2bcb60d10f6a0e2a5f06fb1f5e06c12d809cf2346780321aeb1b20033514e52eadbd516d395
|
7
|
+
data.tar.gz: 49874d2f0102b44446b38beb7af8fa0fa3340067424838012fe8c8409bc4a6a55f3c0a09366e0693bf2c084fab753ac37be9fb22b9313615005bd99bbe7026ef
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,8 +30,8 @@ Key features:
|
|
30
30
|
|
31
31
|
## Requirements
|
32
32
|
|
33
|
-
* Ruby >=1.9.3
|
34
|
-
* Rails 4
|
33
|
+
* Ruby >= 1.9.3
|
34
|
+
* Rails >= 4
|
35
35
|
* Redis
|
36
36
|
* Multi Threaded server ([puma](https://github.com/puma/puma), [rainbows](http://rainbows.rubyforge.org/))
|
37
37
|
|
@@ -148,8 +148,11 @@ dashing_events.*
|
|
148
148
|
where `*` can be anything. This give you all the flexibility you need to push to redis. For example the `send_event` method provided by Dashing uses the following namespace:
|
149
149
|
|
150
150
|
```ruby
|
151
|
-
redis.
|
151
|
+
redis.with do |redis_connection|
|
152
|
+
redis_connection.publish("dashing_events.create", {})
|
153
|
+
end
|
152
154
|
```
|
155
|
+
(where `redis_connection` is a redis connection from a connection pooler.)
|
153
156
|
|
154
157
|
You can configure the redis namespace in `config/initializers/dashing.rb`:
|
155
158
|
|
@@ -3,26 +3,31 @@ module Dashing
|
|
3
3
|
include ActionController::Live
|
4
4
|
|
5
5
|
def index
|
6
|
+
@redis = Dashing.redis
|
7
|
+
|
6
8
|
response.headers['Content-Type'] = 'text/event-stream'
|
7
9
|
response.headers['X-Accel-Buffering'] = 'no'
|
8
10
|
response.stream.write latest_events
|
9
11
|
|
10
|
-
@redis
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
@redis.with do |redis_connection|
|
13
|
+
redis_connection.psubscribe("#{Dashing.config.redis_namespace}.*") do |on|
|
14
|
+
on.pmessage do |pattern, event, data|
|
15
|
+
response.stream.write("data: #{data}\n\n")
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
19
|
rescue IOError
|
17
20
|
logger.info "[Dashing][#{Time.now.utc.to_s}] Stream closed"
|
18
21
|
ensure
|
19
|
-
@redis.quit
|
22
|
+
@redis.shutdown { |redis_connection| redis_connection.quit }
|
20
23
|
response.stream.close
|
21
24
|
end
|
22
25
|
|
23
26
|
def latest_events
|
24
|
-
|
25
|
-
|
27
|
+
@redis.with do |redis_connection|
|
28
|
+
events = redis_connection.hvals("#{Dashing.config.redis_namespace}.latest")
|
29
|
+
events.map { |v| "data: #{v}\n\n" }.join
|
30
|
+
end
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
@@ -14,7 +14,9 @@ module Dashing
|
|
14
14
|
def update
|
15
15
|
data = params[:widget] || {}
|
16
16
|
hash = data.merge(id: params[:name], updatedAt: Time.now.utc.to_i)
|
17
|
-
Dashing.redis.
|
17
|
+
Dashing.redis.with do |redis_connection|
|
18
|
+
redis_connection.publish("#{Dashing.config.redis_namespace}.create", hash.to_json)
|
19
|
+
end
|
18
20
|
|
19
21
|
render nothing: true
|
20
22
|
end
|
data/lib/dashing.rb
CHANGED
@@ -20,8 +20,10 @@ module Dashing
|
|
20
20
|
|
21
21
|
def send_event(id, data)
|
22
22
|
event = data.merge(id: id, updatedAt: Time.now.utc.to_i).to_json
|
23
|
-
redis.
|
24
|
-
|
23
|
+
redis.with do |redis_connection|
|
24
|
+
redis_connection.hset("#{Dashing.config.redis_namespace}.latest", id, event)
|
25
|
+
redis_connection.publish("#{Dashing.config.redis_namespace}.create", event)
|
26
|
+
end
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|
@@ -43,7 +43,7 @@ module Dashing
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def redis
|
46
|
-
@redis ||= ::ConnectionPool
|
46
|
+
@redis ||= ::ConnectionPool.new(size: request_thread_count, timeout: redis_timeout) { new_redis_connection }
|
47
47
|
end
|
48
48
|
|
49
49
|
def new_redis_connection
|
data/lib/dashing/railtie.rb
CHANGED
@@ -21,8 +21,10 @@ module Dashing
|
|
21
21
|
if defined?(::PhusionPassenger)
|
22
22
|
::PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
23
23
|
if forked
|
24
|
-
::Dashing.redis.
|
25
|
-
|
24
|
+
::Dashing.redis.with do |redis_connection|
|
25
|
+
redis_connection.client.disconnect
|
26
|
+
redis_connection.client.connect
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
data/lib/dashing/version.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
RSpec.describe Dashing::WidgetsController do
|
2
2
|
|
3
3
|
let(:redis) { double }
|
4
|
+
let(:redis_connection) { double }
|
4
5
|
|
5
6
|
before do
|
6
|
-
|
7
|
+
stub_redis_with_connection(redis, redis_connection)
|
7
8
|
@routes = Dashing::Engine.routes
|
8
9
|
end
|
9
10
|
|
@@ -49,7 +50,7 @@ RSpec.describe Dashing::WidgetsController do
|
|
49
50
|
context 'when valid' do
|
50
51
|
|
51
52
|
before do
|
52
|
-
expect(
|
53
|
+
expect(redis_connection).to receive(:publish)
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'responds success' do
|
@@ -4,7 +4,8 @@ RSpec.describe Dashing::Configuration do
|
|
4
4
|
|
5
5
|
it { expect(instance.engine_path).to eq('/dashing') }
|
6
6
|
# it { expect(instance.scheduler).to be_a(::Rufus::Scheduler.new) }
|
7
|
-
it { expect(instance.redis).to be_a(::
|
7
|
+
it { expect(instance.redis).to be_a(::ConnectionPool) }
|
8
|
+
it { instance.redis.with { |r| expect(r).to be_a(::Redis) } }
|
8
9
|
|
9
10
|
# Redis
|
10
11
|
it { expect(instance.redis_host).to eq('127.0.0.1') }
|
@@ -6,4 +6,9 @@ module ControllerSpecHelpers
|
|
6
6
|
def stub_redis(stubbed_redis)
|
7
7
|
allow(Dashing.config).to receive(:redis).and_return(stubbed_redis)
|
8
8
|
end
|
9
|
+
|
10
|
+
def stub_redis_with_connection(stubbed_redis, stubbed_redis_connection)
|
11
|
+
stub_redis(stubbed_redis)
|
12
|
+
allow(stubbed_redis).to receive(:with).and_yield(stubbed_redis_connection)
|
13
|
+
end
|
9
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dashing-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre-Louis Gottfrois
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -316,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
316
|
version: '0'
|
317
317
|
requirements: []
|
318
318
|
rubyforge_project:
|
319
|
-
rubygems_version: 2.
|
319
|
+
rubygems_version: 2.6.13
|
320
320
|
signing_key:
|
321
321
|
specification_version: 4
|
322
322
|
summary: The exceptionally handsome dashboard framework for Rails.
|