logplex 0.0.1.pre.2 → 0.0.1.pre.3

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/README.md CHANGED
@@ -41,9 +41,10 @@ You can configure default values for logplex message posting:
41
41
 
42
42
  ```ruby
43
43
  Logplex.configure do |config|
44
- config.logplex_url = 'https://logplex.example.com'
45
- config.process = 'stats'
46
- config.host = 'host'
44
+ config.logplex_url = 'https://logplex.example.com'
45
+ config.process = 'stats'
46
+ config.host = 'host'
47
+ config.publish_timeout = 2
47
48
  end
48
49
  ```
49
50
 
@@ -1,12 +1,14 @@
1
1
  module Logplex
2
2
  class Configuration
3
3
  attr_accessor :logplex_url,
4
- :process,
5
- :host
4
+ :process,
5
+ :host,
6
+ :publish_timeout
6
7
 
7
8
  def initialize
8
- @logplex_url = 'https://east.logplex.io'
9
- @host = 'localhost'
9
+ @logplex_url = 'https://east.logplex.io'
10
+ @host = 'localhost'
11
+ @publish_timeout = 1
10
12
  end
11
13
  end
12
14
 
@@ -2,9 +2,14 @@
2
2
  require 'base64'
3
3
  require 'restclient'
4
4
  require 'logplex/message'
5
+ require 'timeout'
5
6
 
6
7
  module Logplex
7
8
  class Publisher
9
+ PUBLISH_ERRORS = [RestClient::InternalServerError,
10
+ RestClient::Unauthorized,
11
+ Timeout::Error].freeze
12
+
8
13
  def initialize(token, logplex_url=nil)
9
14
  @token = token
10
15
  @logplex_url = logplex_url || Logplex.configuration.logplex_url
@@ -15,9 +20,14 @@ module Logplex
15
20
  messages.map! { |m| Message.new(m, opts.merge(token: @token)) }
16
21
  messages.each(&:validate)
17
22
  if messages.inject(true) { |accum, m| m.valid? }
18
- api_post(
19
- messages.map(&:syslog_frame).join('')
20
- )
23
+ begin
24
+ Timeout::timeout(Logplex.configuration.publish_timeout) do
25
+ api_post(messages.map(&:syslog_frame).join(''))
26
+ true
27
+ end
28
+ rescue *PUBLISH_ERRORS
29
+ false
30
+ end
21
31
  end
22
32
  end
23
33
 
@@ -1,3 +1,3 @@
1
1
  module Logplex
2
- VERSION = "0.0.1.pre.2"
2
+ VERSION = "0.0.1.pre.3"
3
3
  end
@@ -5,42 +5,82 @@ require 'support/fake_logplex'
5
5
 
6
6
  describe Logplex::Publisher, '#publish' do
7
7
  before do
8
- ShamRack.mount(FakeLogplex.new, 'logplex.example.com', 443)
9
-
10
8
  Logplex.configure do |config|
11
9
  config.process = "postgres"
12
10
  config.host = "host"
13
11
  end
14
12
  end
15
13
 
16
- after do
17
- ShamRack.unmount_all
18
- FakeLogplex.clear!
19
- restore_default_config
20
- end
14
+ context 'with a working logplex' do
15
+ before do
16
+ ShamRack.mount(FakeLogplex.new, 'logplex.example.com', 443)
21
17
 
22
- it 'encodes a message and publishes it' do
23
- FakeLogplex.register_token('t.some-token')
18
+ end
24
19
 
25
- message = 'I have a message for you'
26
- publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
27
- publisher.publish(message)
20
+ after do
21
+ ShamRack.unmount_all
22
+ FakeLogplex.clear!
23
+ restore_default_config
24
+ end
28
25
 
29
- expect(FakeLogplex).to have_received_message(message)
30
- end
26
+ it 'encodes a message and publishes it' do
27
+ FakeLogplex.register_token('t.some-token')
31
28
 
32
- it 'sends many messages in one request when passed an array' do
33
- FakeLogplex.register_token('t.some-token')
34
- messages = ['I have a message for you', 'here is another', 'some final thoughts']
29
+ message = 'I have a message for you'
30
+ publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
31
+ publisher.publish(message)
35
32
 
36
- publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
33
+ expect(FakeLogplex).to have_received_message(message)
34
+ end
37
35
 
38
- publisher.publish(messages)
36
+ it 'sends many messages in one request when passed an array' do
37
+ FakeLogplex.register_token('t.some-token')
38
+ messages = ['I have a message for you', 'here is another', 'some final thoughts']
39
39
 
40
- messages.each do |message|
41
- expect(FakeLogplex).to have_received_message(message)
40
+ publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
41
+
42
+ publisher.publish(messages)
43
+
44
+ messages.each do |message|
45
+ expect(FakeLogplex).to have_received_message(message)
46
+ end
47
+
48
+ expect(FakeLogplex.requests_received).to eq(1)
42
49
  end
43
50
 
44
- expect(FakeLogplex.requests_received).to eq(1)
51
+ it 'returns true' do
52
+ FakeLogplex.register_token('t.some-token')
53
+
54
+ message = 'I have a message for you'
55
+ publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
56
+ expect(publisher.publish(message)).to be_true
57
+ end
58
+
59
+ it "returns false when there's an auth error" do
60
+ message = 'I have a message for you'
61
+ publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
62
+ expect(publisher.publish(message)).to be_false
63
+ end
64
+ end
65
+
66
+ context 'when the logplex service is acting up' do
67
+ before do
68
+ ShamRack.at('logplex.example.com', 443) do
69
+ [500, {}, []]
70
+ end
71
+ end
72
+
73
+ after { ShamRack.unmount_all }
74
+
75
+ it 'returns false' do
76
+ publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
77
+ expect(publisher.publish('hi')).to be_false
78
+ end
79
+ end
80
+
81
+ it "handles timeouts" do
82
+ RestClient.stub(:post).and_raise Timeout::Error
83
+ publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
84
+ expect(publisher.publish('hi')).to be_false
45
85
  end
46
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logplex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.2
4
+ version: 0.0.1.pre.3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-01 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: valcro
16
- requirement: &70106294975600 !ruby/object:Gem::Requirement
16
+ requirement: &70108795420800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70106294975600
24
+ version_requirements: *70108795420800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &70106294975040 !ruby/object:Gem::Requirement
27
+ requirement: &70108795449080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70106294975040
35
+ version_requirements: *70108795449080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70106294974360 !ruby/object:Gem::Requirement
38
+ requirement: &70108795448440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70106294974360
46
+ version_requirements: *70108795448440
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sham_rack
49
- requirement: &70106294973520 !ruby/object:Gem::Requirement
49
+ requirement: &70108795447760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70106294973520
57
+ version_requirements: *70108795447760
58
58
  description: Publish and Consume Logplex messages
59
59
  email:
60
60
  - harold.gimenez@gmail.com