banter 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Gemfile +1 -0
- data/lib/banter.rb +17 -1
- data/lib/banter/subscriber.rb +1 -1
- data/lib/banter/version.rb +1 -1
- data/lib/banter/web/models/banter_worker.rb +0 -1
- data/lib/banter/web/serializers/banter_worker_serializer.rb +11 -1
- data/spec/banter/subscriber_spec.rb +1 -0
- data/spec/banter/web/serializers/banter_message_serializer_spec.rb +42 -0
- data/spec/banter/web/serializers/banter_worker_serializer_spec.rb +44 -0
- data/spec/factories/banter_messages.rb +2 -2
- data/spec/factories/banter_workers.rb +4 -0
- data/spec/spec_helper.rb +1 -0
- data/web/assets/javascripts/banter.js +1 -1
- data/web/assets/javascripts/dashboard_app/controllers/messages_controller.coffee +50 -49
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d85903bb31f3228276c85be5bafef8248ce7d59
|
4
|
+
data.tar.gz: b0360f892d785b4f43cd1edea68a2dd46770a183
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35b341cecc7fc70ded556ccdd4fc982e10a287d792e98806124b62a6cd12cad61be3e77510f8aee20244578705b0d8407ddb08272333a2a638e7dd9f98cc16d8
|
7
|
+
data.tar.gz: 45116f712ef2bb23029c23ad55ac820a942230602500439f069240eb2499c15143a05ed06e9e8ad4f6ccd575ed4da11334ab46ffae6547bf5c118e973f7bf9a4
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/lib/banter.rb
CHANGED
@@ -32,6 +32,12 @@ module Banter
|
|
32
32
|
Publisher.instance.publish(Banter::Context.instance, routing_key, payload)
|
33
33
|
end
|
34
34
|
|
35
|
+
# Delay actual publishing of messages to rabbitmq. Any messages published using Banter.publish will be delayed till
|
36
|
+
# after the block. if any errors happen in this block, then no messages are published to the rabbitmq.
|
37
|
+
# Usage:
|
38
|
+
# Banter.delay_messages do
|
39
|
+
# Banter.publish('foo.bar', {}) # -> message will not be published here
|
40
|
+
# end # -> message will be published here
|
35
41
|
def self.delay_messages
|
36
42
|
Publisher.instance.delay_messages{ yield }
|
37
43
|
end
|
@@ -46,4 +52,14 @@ module Banter
|
|
46
52
|
def self.logger=(logger)
|
47
53
|
Banter::Configuration.logger = ActiveSupport::TaggedLogging.new(logger)
|
48
54
|
end
|
49
|
-
|
55
|
+
|
56
|
+
# A convenience methods, specially for non-rails applications to configure Banter
|
57
|
+
# Usage:
|
58
|
+
# Banter.configure do |config|
|
59
|
+
# config.default_queue_ttl = 2.hours
|
60
|
+
# end
|
61
|
+
|
62
|
+
def self.configure
|
63
|
+
yield Banter::Configuration
|
64
|
+
end
|
65
|
+
end
|
data/lib/banter/subscriber.rb
CHANGED
@@ -110,7 +110,7 @@ module Banter
|
|
110
110
|
|
111
111
|
def self.validate_routing_key_name(key)
|
112
112
|
return true if key.blank?
|
113
|
-
key.match(/\A([a-z]+\.?)*([a-z]+)\Z/).present?
|
113
|
+
key.match(/\A([a-z]+\.?)*([a-z\_]+)\Z/).present?
|
114
114
|
end
|
115
115
|
|
116
116
|
def self.generated_queue_name(routing_key, queue_name)
|
data/lib/banter/version.rb
CHANGED
@@ -18,12 +18,22 @@ module Banter
|
|
18
18
|
stopped_at: worker.stopped_at,
|
19
19
|
worker_classes: Array.wrap(worker.worker_classes),
|
20
20
|
hostname: worker.hostname,
|
21
|
-
current_message:
|
21
|
+
current_message: current_message_serialized,
|
22
22
|
job_count: worker.job_count,
|
23
23
|
success_count: worker.success_count,
|
24
24
|
failed_count: worker.failed_count
|
25
25
|
}
|
26
26
|
end
|
27
|
+
|
28
|
+
def current_message_serialized
|
29
|
+
return if worker.current_message.blank?
|
30
|
+
worker.current_message.tap do |hash|
|
31
|
+
_id = hash.delete('_id')
|
32
|
+
if _id
|
33
|
+
hash["id"] = _id.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
27
37
|
end
|
28
38
|
end
|
29
39
|
end
|
@@ -199,6 +199,7 @@ describe Banter::Subscriber do
|
|
199
199
|
it { expect(Klass.send(:validate_routing_key_name, 'abcdef.abcdef.asd')).to eq(true) }
|
200
200
|
it { expect(Klass.send(:validate_routing_key_name, 'abcdef.abcdef/')).to eq(false) }
|
201
201
|
it { expect(Klass.send(:validate_routing_key_name, 'abcdef.abcdef.a123')).to eq(false) }
|
202
|
+
it { expect(Klass.send(:validate_routing_key_name, 'abcdef.stuff_happened')).to eq(true) }
|
202
203
|
it { expect(Klass.send(:validate_routing_key_name, 'abcdef.')).to eq(false) }
|
203
204
|
it { expect(Klass.send(:validate_routing_key_name, 'abcAf')).to eq(false) }
|
204
205
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Banter::Web::Serializers::BanterMessageSerializer do
|
4
|
+
describe '#to_hash' do
|
5
|
+
def self.it_should_have_all_the_keys
|
6
|
+
its([:id]) { should eq(banter_message.id.to_s) }
|
7
|
+
its([:subscriber_class]) { should eq(banter_message.subscriber_class) }
|
8
|
+
its([:queue_name]) { should eq(banter_message.queue_name)}
|
9
|
+
its([:subscribed_key]) { should eq(banter_message.subscribed_key)}
|
10
|
+
its([:payload_key]) { should eq(banter_message.payload_key)}
|
11
|
+
its([:context]) { should eq(banter_message.context)}
|
12
|
+
its([:payload_key]) { should eq(banter_message.payload_key)}
|
13
|
+
its([:payload]) { should eq(banter_message.payload)}
|
14
|
+
its([:started_at]) { should eq(banter_message.started_at)}
|
15
|
+
its([:error_message]) { should eq(banter_message.error_message)}
|
16
|
+
its([:worker_id]) { should eq(banter_message.worker_id)}
|
17
|
+
its([:progress_total]) { should eq(banter_message.progress_total)}
|
18
|
+
its([:progress_at]) { should eq(banter_message.progress_at)}
|
19
|
+
its([:progress]) { should eq(banter_message.progress)}
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { Banter::Web::Serializers::BanterMessageSerializer.new(banter_message).to_hash }
|
23
|
+
let(:banter_message) { FactoryGirl.create(:banter_message) }
|
24
|
+
|
25
|
+
context "message is not finished" do
|
26
|
+
it_should_have_all_the_keys
|
27
|
+
its([:done_at]) { should be_nil }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "finished" do
|
31
|
+
let(:banter_message) { FactoryGirl.create(:banter_message, :done) }
|
32
|
+
it_should_have_all_the_keys
|
33
|
+
its([:done_at]) { should_not be_nil }
|
34
|
+
its([:done_at]) { should eq(banter_message.done_at) }
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Banter::Web::Serializers::BanterWorkerSerializer do
|
4
|
+
describe '#to_hash' do
|
5
|
+
def self.it_should_have_all_the_keys
|
6
|
+
its([:id]) { should eq(worker.id.to_s) }
|
7
|
+
its([:process_name]) { should eq(worker.process_name) }
|
8
|
+
its([:pid]) { should eq(worker.pid) }
|
9
|
+
its([:started_at]) { should eq(worker.started_at) }
|
10
|
+
its([:stopped_at]) { should eq(worker.stopped_at) }
|
11
|
+
its([:worker_classes]) { should eq(Array.wrap(worker.worker_classes)) }
|
12
|
+
its([:hostname]) { should eq(worker.hostname) }
|
13
|
+
its([:job_count]) { should eq(worker.job_count) }
|
14
|
+
its([:success_count]) { should eq(worker.success_count) }
|
15
|
+
its([:failed_count]) { should eq(worker.failed_count) }
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { Banter::Web::Serializers::BanterWorkerSerializer.new(worker).to_hash }
|
19
|
+
let(:worker) { FactoryGirl.create(:banter_worker) }
|
20
|
+
|
21
|
+
context "working" do
|
22
|
+
context "without current message" do
|
23
|
+
it_should_have_all_the_keys
|
24
|
+
its([:stopped_at]) { should be_nil }
|
25
|
+
its([:current_message]) { should be_nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with current message' do
|
29
|
+
let(:message) { FactoryGirl.create(:banter_message)}
|
30
|
+
let(:worker) { FactoryGirl.create(:banter_worker, current_message: message.attributes)}
|
31
|
+
it_should_have_all_the_keys
|
32
|
+
its([:stopped_at]) { should be_nil }
|
33
|
+
it { expect(subject[:current_message]['id']).to eq(message.attributes['id'])}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "finished" do
|
38
|
+
let(:banter_message) { FactoryGirl.create(:banter_message, :stopped) }
|
39
|
+
it_should_have_all_the_keys
|
40
|
+
its([:stopped_at]) { should be_nil }
|
41
|
+
its([:current_message]) { should be_nil }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -5,7 +5,7 @@ FactoryGirl.define do
|
|
5
5
|
payload_key "fu.Q.again"
|
6
6
|
payload { { a: 1, b: 2 } }
|
7
7
|
context {{ app: 'banter' }}
|
8
|
-
started_at Time.now - 2
|
8
|
+
started_at { Time.now - 2 }
|
9
9
|
status BanterMessage::STATUS_STARTED
|
10
10
|
worker_id { FactoryGirl.create(:banter_worker).id }
|
11
11
|
|
@@ -22,7 +22,7 @@ FactoryGirl.define do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
trait :done do
|
25
|
-
done_at Time.now
|
25
|
+
done_at { Time.now }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -60,7 +60,7 @@ angular.module("ngPrettyJson",[]).directive("prettyJson",["ngPrettyJsonFunctions
|
|
60
60
|
|
61
61
|
}).call(this);
|
62
62
|
(function() {
|
63
|
-
angular.module('dashboardApp').controller('messagesController', function($scope, $rootScope, $http, $routeParams, $timeout, messages, messagesService, commonMethodsService, messageMethodsService, workerMethodsService) {
|
63
|
+
angular.module('dashboardApp').controller('messagesController', function($scope, $rootScope, $http, $routeParams, $timeout, messages, messagesService, workersService, commonMethodsService, messageMethodsService, workerMethodsService) {
|
64
64
|
var autoUpdate, fetchMessages, workerId;
|
65
65
|
commonMethodsService.setup($scope);
|
66
66
|
messageMethodsService.setup($scope);
|
@@ -1,57 +1,58 @@
|
|
1
|
-
angular.module('dashboardApp').controller 'messagesController',
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
$scope.messages = messages
|
7
|
-
$scope.page = 1
|
8
|
-
$scope.worker = null
|
9
|
-
|
10
|
-
workerId = $routeParams.worker_id
|
11
|
-
$scope.subscriber = $routeParams.subscriber
|
12
|
-
autoUpdate = true
|
13
|
-
|
14
|
-
if workerId
|
15
|
-
workersService.getWorker(workerId).success (response) ->
|
16
|
-
$scope.worker = response.worker
|
17
|
-
|
18
|
-
fetchMessages = ->
|
19
|
-
messagesService.getMessages($scope.page, workerId, $scope.subscriber).success (response) ->
|
20
|
-
$scope.messages = response.messages
|
21
|
-
$scope.worker = response.worker
|
22
|
-
|
23
|
-
$rootScope.$on 'start-messagesController', ->
|
24
|
-
$scope.resumeUpdating()
|
25
|
-
$rootScope.$on 'stop-messagesController', ->
|
26
|
-
$scope.pauseUpdating()
|
27
|
-
|
28
|
-
$scope.updateMessages = (resumeUpdate = true) ->
|
29
|
-
if autoUpdate
|
30
|
-
fetchMessages()
|
31
|
-
$scope.resumeUpdating()
|
1
|
+
angular.module('dashboardApp').controller 'messagesController',
|
2
|
+
($scope, $rootScope, $http, $routeParams, $timeout, messages, messagesService, workersService, commonMethodsService, messageMethodsService, workerMethodsService) ->
|
3
|
+
commonMethodsService.setup($scope)
|
4
|
+
messageMethodsService.setup($scope)
|
5
|
+
workerMethodsService.setup($scope)
|
32
6
|
|
33
|
-
|
34
|
-
|
7
|
+
$scope.messages = messages
|
8
|
+
$scope.page = 1
|
9
|
+
$scope.worker = null
|
35
10
|
|
36
|
-
|
11
|
+
workerId = $routeParams.worker_id
|
12
|
+
$scope.subscriber = $routeParams.subscriber
|
37
13
|
autoUpdate = true
|
38
|
-
$timeout($scope.updateMessages, 5000)
|
39
14
|
|
40
|
-
|
41
|
-
|
42
|
-
|
15
|
+
if workerId
|
16
|
+
workersService.getWorker(workerId).success (response) ->
|
17
|
+
$scope.worker = response.worker
|
43
18
|
|
44
|
-
|
45
|
-
|
46
|
-
|
19
|
+
fetchMessages = ->
|
20
|
+
messagesService.getMessages($scope.page, workerId, $scope.subscriber).success (response) ->
|
21
|
+
$scope.messages = response.messages
|
22
|
+
$scope.worker = response.worker
|
47
23
|
|
48
|
-
|
49
|
-
|
50
|
-
$
|
51
|
-
|
24
|
+
$rootScope.$on 'start-messagesController', ->
|
25
|
+
$scope.resumeUpdating()
|
26
|
+
$rootScope.$on 'stop-messagesController', ->
|
27
|
+
$scope.pauseUpdating()
|
52
28
|
|
53
|
-
|
54
|
-
|
55
|
-
|
29
|
+
$scope.updateMessages = (resumeUpdate = true) ->
|
30
|
+
if autoUpdate
|
31
|
+
fetchMessages()
|
32
|
+
$scope.resumeUpdating()
|
33
|
+
|
34
|
+
$scope.pauseUpdating = ->
|
35
|
+
autoUpdate = false
|
36
|
+
|
37
|
+
$scope.resumeUpdating = ->
|
38
|
+
autoUpdate = true
|
39
|
+
$timeout($scope.updateMessages, 5000)
|
40
|
+
|
41
|
+
$scope.resumeUpdating() if autoUpdate
|
42
|
+
$scope.isAutoUpdating = ->
|
43
|
+
autoUpdate
|
44
|
+
|
45
|
+
$scope.getNextPage = ->
|
46
|
+
$scope.page += 1
|
47
|
+
fetchMessages()
|
48
|
+
|
49
|
+
$scope.getPreviousPage = ->
|
50
|
+
$scope.page -= 1
|
51
|
+
$scope.page = 1 if $scope.page < 1
|
52
|
+
fetchMessages()
|
53
|
+
|
54
|
+
$scope.getFirstPage = ->
|
55
|
+
$scope.page = 1
|
56
|
+
fetchMessages()
|
56
57
|
|
57
|
-
|
58
|
+
return
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Honest Company
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-07-
|
14
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -238,6 +238,8 @@ files:
|
|
238
238
|
- spec/banter/server/subscriber_server_spec.rb
|
239
239
|
- spec/banter/subscriber_spec.rb
|
240
240
|
- spec/banter/web/application_spec.rb
|
241
|
+
- spec/banter/web/serializers/banter_message_serializer_spec.rb
|
242
|
+
- spec/banter/web/serializers/banter_worker_serializer_spec.rb
|
241
243
|
- spec/config.yml
|
242
244
|
- spec/factories/banter_messages.rb
|
243
245
|
- spec/factories/banter_workers.rb
|
@@ -301,6 +303,8 @@ test_files:
|
|
301
303
|
- spec/banter/server/subscriber_server_spec.rb
|
302
304
|
- spec/banter/subscriber_spec.rb
|
303
305
|
- spec/banter/web/application_spec.rb
|
306
|
+
- spec/banter/web/serializers/banter_message_serializer_spec.rb
|
307
|
+
- spec/banter/web/serializers/banter_worker_serializer_spec.rb
|
304
308
|
- spec/config.yml
|
305
309
|
- spec/factories/banter_messages.rb
|
306
310
|
- spec/factories/banter_workers.rb
|