banter 1.0.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51871d5d895dbf72454f67a614a14aa8af5cd6ee
4
- data.tar.gz: 37321de3cd2605a5b7d99ffce5e979167b7597df
3
+ metadata.gz: 4d85903bb31f3228276c85be5bafef8248ce7d59
4
+ data.tar.gz: b0360f892d785b4f43cd1edea68a2dd46770a183
5
5
  SHA512:
6
- metadata.gz: 9dba68030359665879dbd785c613523282f97a5b91a721824c91dd4375e87a8299e39f68af759595ffe5963b584b7981b526a7a5d0071f05b2a4a02cc1c95669
7
- data.tar.gz: 16ba97865260c2e81463d374f1c4806cf17ad65628022aa6abc90da7e6d8af8741a0166afd67887f59a5d87c5f9f8dc53ccb989e7609f376e379212d5707173a
6
+ metadata.gz: 35b341cecc7fc70ded556ccdd4fc982e10a287d792e98806124b62a6cd12cad61be3e77510f8aee20244578705b0d8407ddb08272333a2a638e7dd9f98cc16d8
7
+ data.tar.gz: 45116f712ef2bb23029c23ad55ac820a942230602500439f069240eb2499c15143a05ed06e9e8ad4f6ccd575ed4da11334ab46ffae6547bf5c118e973f7bf9a4
@@ -12,7 +12,6 @@ notifications:
12
12
  email:
13
13
  - webadmin@honest.com
14
14
  - tushar@honest.com
15
- on_success: always
16
15
  on_failure: always
17
16
 
18
17
 
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gem 'coffee-script'
7
7
  gem 'json'
8
8
  group :test do
9
9
  gem 'rack-test'
10
+ gem 'rspec-its'
10
11
  gem 'sinatra'
11
12
  gem 'haml'
12
13
  gem 'mongoid', github: 'mongoid/mongoid'
@@ -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
- end
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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Banter
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -45,7 +45,6 @@ class BanterWorker
45
45
  # @param [BanterMessage] banter_message Message that is currently being executed
46
46
  def self.record_current!(banter_message)
47
47
  current.current_message = banter_message.attributes
48
-
49
48
  current.save!
50
49
  end
51
50
 
@@ -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: worker.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
@@ -9,5 +9,9 @@ FactoryGirl.define do
9
9
  trait :stopped do
10
10
  stopped_at { Time.now }
11
11
  end
12
+
13
+ trait :with_current_message do
14
+ current_message { FactoryGirl.create(:banter_message).attributes }
15
+ end
12
16
  end
13
17
  end
@@ -15,6 +15,7 @@ require 'rack/test'
15
15
  require 'banter/web'
16
16
  require 'timecop'
17
17
  require 'factory_girl'
18
+ require 'rspec/its'
18
19
 
19
20
  module RSpecMixin
20
21
  include Rack::Test::Methods
@@ -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', ($scope, $rootScope, $http, $routeParams, $timeout, messages, messagesService, commonMethodsService, messageMethodsService, workerMethodsService) ->
2
- commonMethodsService.setup($scope)
3
- messageMethodsService.setup($scope)
4
- workerMethodsService.setup($scope)
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
- $scope.pauseUpdating = ->
34
- autoUpdate = false
7
+ $scope.messages = messages
8
+ $scope.page = 1
9
+ $scope.worker = null
35
10
 
36
- $scope.resumeUpdating = ->
11
+ workerId = $routeParams.worker_id
12
+ $scope.subscriber = $routeParams.subscriber
37
13
  autoUpdate = true
38
- $timeout($scope.updateMessages, 5000)
39
14
 
40
- $scope.resumeUpdating() if autoUpdate
41
- $scope.isAutoUpdating = ->
42
- autoUpdate
15
+ if workerId
16
+ workersService.getWorker(workerId).success (response) ->
17
+ $scope.worker = response.worker
43
18
 
44
- $scope.getNextPage = ->
45
- $scope.page += 1
46
- fetchMessages()
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
- $scope.getPreviousPage = ->
49
- $scope.page -= 1
50
- $scope.page = 1 if $scope.page < 1
51
- fetchMessages()
24
+ $rootScope.$on 'start-messagesController', ->
25
+ $scope.resumeUpdating()
26
+ $rootScope.$on 'stop-messagesController', ->
27
+ $scope.pauseUpdating()
52
28
 
53
- $scope.getFirstPage = ->
54
- $scope.page = 1
55
- fetchMessages()
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
- return
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.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-17 00:00:00.000000000 Z
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