radar-app 0.8.0 → 0.11.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
- SHA1:
3
- metadata.gz: d43b3d2a3f45092f6b6c5103139212ed172d8df2
4
- data.tar.gz: 2761fcb6de99bae630fca6ca42b5d0b33549a99f
2
+ SHA256:
3
+ metadata.gz: 747689e670764ac159b53aacd64031b35fba08dc5738b8283ecf815ed1a1a60f
4
+ data.tar.gz: b1d9e7acf27bf80ac06f951911e7a03e321522deb5062b986a37607f367fa79b
5
5
  SHA512:
6
- metadata.gz: 01a4a69686ee07c2f5671cef8990b68a702a3d821c5abf7b7be886197765f11d23131301875f44f2478cea415952fe58ebab53be565ecfc16608d78714d712c3
7
- data.tar.gz: 2317f952b12ad4b60334ab3f3dc2728cd54190233760005f55d27ec12fdfea3b6e9a1560282f5401315840dba74f328731b56df1eac8c5a6bfc7757157f7a290
6
+ metadata.gz: 2f0098ac27d965df611efd6b020080e4f3d5364474302efc87d780a44b4b91f994b99d027489d8765c35c96642e30a80b27535bc6a1dffb7680c72c0baa5472d
7
+ data.tar.gz: 010eb0a3b41c7fd06ead5b75a5a954715b15013675f9ddd00c92dd48826d5b674c27bac3bd37bf472340a14f7b26fa7af9e518d0c8e7429c16cdff799141eff4
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec do
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
@@ -8,3 +8,12 @@ guard 'rake', :task => 'install' do
8
8
  watch(%r{^lib/(.+)\.rb$})
9
9
  watch(/^bin/)
10
10
  end
11
+
12
+ # Note: The cmd option is now required due to the increasing number of ways
13
+ # rspec may be run, below are examples of the most common uses.
14
+ # * bundler: 'bundle exec rspec'
15
+ # * bundler binstubs: 'bin/rspec'
16
+ # * spring: 'bin/rspec' (This will use spring if running and you have
17
+ # installed the spring binstubs per the docs)
18
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
19
+ # * 'just' rspec: 'rspec'
@@ -7,7 +7,9 @@ require 'radar/app/analyzer_controller'
7
7
  require 'radar/app/server'
8
8
  require 'radar/app/bootstrap'
9
9
  require 'radar/app/analyzer'
10
+ require 'radar/app/healthz'
10
11
  require 'radar/app/processor_factory'
12
+ require 'radar/app/multiplexed_processor'
11
13
 
12
14
  require 'radar-api'
13
15
  require 'connection_pool'
@@ -58,6 +60,10 @@ module Radar
58
60
  @portfolio_service ||= connection_pool('PortfolioService')
59
61
  end
60
62
 
63
+ def self.integration_status_service
64
+ @integration_status_service ||= connection_pool('IntegrationStatusService')
65
+ end
66
+
61
67
  protected
62
68
 
63
69
  def self.connection_pool(client_class)
@@ -0,0 +1,9 @@
1
+ module Radar
2
+ module App
3
+ class Healthz
4
+ def status
5
+ Radar::API::HealthStatus::HEALTHY
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ class Radar::App::MultiplexedProcessor < Thrift::MultiplexedProcessor
2
+ def process(iprot, oprot)
3
+ begin
4
+ name, type, seqid = iprot.read_message_begin
5
+ super(Thrift::StoredMessageProtocol.new(iprot, [name, type, seqid]), oprot)
6
+ rescue Thrift::Exception => e
7
+ write_error(Thrift::ApplicationException.new(Thrift::ApplicationException::INTERNAL_ERROR, e.message), oprot, name, seqid)
8
+ end
9
+ end
10
+
11
+ protected
12
+
13
+ def write_error(err, oprot, name, seqid)
14
+ oprot.write_message_begin(name, Thrift::MessageTypes::EXCEPTION, seqid)
15
+ err.write(oprot)
16
+ oprot.write_message_end
17
+ oprot.trans.flush
18
+ end
19
+
20
+ end
@@ -1,10 +1,34 @@
1
1
  require 'thrift/exceptions'
2
+ require 'radar-api'
2
3
 
3
4
  module Radar
4
5
  module App
5
6
  module ProcessorFactory
7
+
8
+ class AppErrorHandler
9
+ def initialize(target)
10
+ @target = target
11
+ end
12
+
13
+ def method_missing(m, *args, &block)
14
+ begin
15
+ @target.send(m, *args, &block)
16
+ rescue => e
17
+ if e.kind_of?(Thrift::Exception)
18
+ raise e
19
+ else
20
+ raise Radar::API::ApplicationError.new(message: e.message, stacktrace: e.backtrace)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
6
26
  def self.create_processor(superclass)
7
27
  Class.new(superclass) do
28
+ def initialize(handler)
29
+ super(AppErrorHandler.new(handler))
30
+ end
31
+
8
32
  def write_error(err, oprot, name, seqid)
9
33
  super
10
34
  raise if err.type == Thrift::ApplicationException::INTERNAL_ERROR
@@ -8,6 +8,7 @@ module Radar
8
8
  register(Radar::App::Tasks::New, :new, 'new APP', 'Create a new app')
9
9
  register(Radar::App::Tasks::Generate, :generate, 'generate TYPE NAME', 'Generate source files')
10
10
  register(Radar::App::Tasks::Server, :server, 'server', 'Start the app server')
11
+ register(Radar::App::Tasks::Status, :status, 'status', 'Check the server status')
11
12
  register(Radar::App::Tasks::Console, :console, 'console', 'Start the console for test')
12
13
  end
13
14
  end
@@ -7,7 +7,7 @@ module Radar
7
7
  include Radar::App::Logger
8
8
 
9
9
  def start
10
- multiplexer = Thrift::MultiplexedProcessor.new
10
+ multiplexer = MultiplexedProcessor.new
11
11
  analyzer_controller = Radar::App::AnalyzerController.new
12
12
  multiplexer.register_processor(
13
13
  'PortfolioAnalyzer',
@@ -28,6 +28,11 @@ module Radar
28
28
  new(Radar::App.transaction_file_importer)
29
29
  )
30
30
  end
31
+ multiplexer.register_processor(
32
+ 'Healthz',
33
+ ProcessorFactory.create_processor(Radar::API::Healthz::Processor).
34
+ new(Radar::App::Healthz.new)
35
+ )
31
36
  transport = Thrift::ServerSocket.new(port)
32
37
  server = Thrift::NonblockingServer.new(multiplexer, transport, Thrift::FramedTransportFactory.new)
33
38
  logger.info { "Starting app on port #{port}..." }
@@ -2,3 +2,4 @@ require 'radar/app/tasks/new'
2
2
  require 'radar/app/tasks/server'
3
3
  require 'radar/app/tasks/generate'
4
4
  require 'radar/app/tasks/console'
5
+ require 'radar/app/tasks/status'
@@ -1,3 +1,5 @@
1
+ require 'sigdump'
2
+
1
3
  module Radar
2
4
  module App
3
5
  module Tasks
@@ -6,6 +8,7 @@ module Radar
6
8
  namespace :server
7
9
 
8
10
  def start_server
11
+ Sigdump.setup('TTIN', '-')
9
12
  Radar::App::Bootstrap.startup
10
13
  Radar::App::Server.new(ENV['PORT'] || 5000).start
11
14
  end
@@ -0,0 +1,33 @@
1
+ require 'thrift'
2
+ require 'radar-api'
3
+ require 'radar/api/healthz'
4
+
5
+ module Radar
6
+ module App
7
+ module Tasks
8
+ class Status < Thor::Group
9
+ include Thor::Actions
10
+ namespace :status
11
+
12
+ def status
13
+ transport = Thrift::FramedTransport.new(Thrift::Socket.new('127.0.0.1', ENV['PORT'] || 5000))
14
+ protocol = Thrift::MultiplexedProtocol.new(Thrift::BinaryProtocolAccelerated.new(transport), 'Healthz')
15
+ client = Radar::Api::Healthz::Client.new(protocol)
16
+ begin
17
+ transport.open
18
+ client.status
19
+ rescue Thrift::TransportException => e
20
+ case e.type
21
+ when 1
22
+ puts "Server is down!"
23
+ else
24
+ puts "Server is not ready: #{e}"
25
+ end
26
+ exit 100 + e.type
27
+ end
28
+ puts "Server is up!"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Radar
2
2
  module App
3
- VERSION = "0.8.0"
3
+ VERSION = "0.11.1"
4
4
  end
5
5
  end
@@ -24,9 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec"
25
25
 
26
26
  spec.add_dependency "thor", "~> 0.19"
27
- spec.add_dependency "radar-api", "~> 0.2"
27
+ spec.add_dependency "radar-api", ">= 0.10.0"
28
28
  spec.add_dependency "thin", "1.6.2"
29
29
  spec.add_dependency "connection_pool", "~> 2.0"
30
30
  spec.add_dependency "activesupport", "~> 4.1"
31
31
  spec.add_dependency "RaymondChou-thrift_client", "~> 0.9"
32
+ spec.add_dependency "sigdump", "~> 0.2.4"
32
33
  end
@@ -1,11 +1,31 @@
1
1
  require 'radar/app/processor_factory'
2
2
 
3
3
  describe Radar::App::ProcessorFactory do
4
+ let(:handler_class) do
5
+ Class.new do
6
+ end
7
+ end
4
8
 
5
9
  let(:parent_processor_class) do
6
10
  Class.new do
7
11
  attr_reader :write_error_called
8
12
 
13
+ def raise_an_error
14
+ raise 'an error'
15
+ end
16
+
17
+ def initialize(handler)
18
+ end
19
+
20
+ def process_an_error
21
+ begin
22
+ raise 'an error'
23
+ rescue => e
24
+ x = Thrift::ApplicationException.new(Thrift::ApplicationException::INTERNAL_ERROR, 'Internal error')
25
+ write_error(x, nil, nil, nil)
26
+ end
27
+ end
28
+
9
29
  def process_an_error
10
30
  begin
11
31
  raise 'an error'
@@ -29,7 +49,7 @@ describe Radar::App::ProcessorFactory do
29
49
 
30
50
  describe '#create_processor' do
31
51
  describe 'it creates a processor that' do
32
- let(:processor) { Radar::App::ProcessorFactory.create_processor(parent_processor_class).new }
52
+ let(:processor) { Radar::App::ProcessorFactory.create_processor(parent_processor_class).new(nil) }
33
53
  it 'raises the exception on error' do
34
54
  expect { processor.process_an_error }.to raise_error 'an error'
35
55
  end
@@ -48,4 +68,22 @@ describe Radar::App::ProcessorFactory do
48
68
  end
49
69
  end
50
70
  end
71
+ describe 'AppErrorHandler' do
72
+ let(:error_handler) { Radar::App::ProcessorFactory::AppErrorHandler.new }
73
+ let(:target) { double() }
74
+ context 'then target raises a non-Thrift exception' do
75
+ it 'raises an ApplicationError' do
76
+ allow(target).to receive(:raise_an_error).and_raise 'an error'
77
+ error_handler = Radar::App::ProcessorFactory::AppErrorHandler.new(target)
78
+ expect { error_handler.raise_an_error }.to raise_error(Radar::Api::ApplicationError)
79
+ end
80
+ context 'then target raises a Thrift exception' do
81
+ it 'raises the original error' do
82
+ allow(target).to receive(:raise_an_error).and_raise Radar::Api::AuthenticationError.new
83
+ error_handler = Radar::App::ProcessorFactory::AppErrorHandler.new(target)
84
+ expect { error_handler.raise_an_error }.to raise_error(Radar::Api::AuthenticationError)
85
+ end
86
+ end
87
+ end
88
+ end
51
89
  end
@@ -0,0 +1,26 @@
1
+ require 'radar/app/runner'
2
+ require 'radar/app'
3
+ require 'socket'
4
+
5
+ describe Radar::App::Tasks::Status do
6
+ describe '#status' do
7
+ let(:port) do
8
+ server = TCPServer.new('127.0.0.1', 0)
9
+ port = server.addr[1]
10
+ server.close
11
+ port
12
+ end
13
+ before :each do
14
+ allow(ENV).to receive(:[]).and_return nil
15
+ allow(ENV).to receive(:[]).with('PORT').and_return port
16
+ end
17
+ it 'exits with error code when cannot connect to server' do
18
+ expect { Radar::App::Runner.start(%w{status}) }.to raise_error SystemExit
19
+ end
20
+ it 'does not exit with error when PONG is received' do
21
+ Thread.new { @server = Radar::App::Server.new(port).start }
22
+ sleep 0.3
23
+ expect { Radar::App::Runner.start(%w{status}) }.not_to raise_error
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radar-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Mendonca
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-02 00:00:00.000000000 Z
12
+ date: 2020-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -85,16 +85,16 @@ dependencies:
85
85
  name: radar-api
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: '0.2'
90
+ version: 0.10.0
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: '0.2'
97
+ version: 0.10.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: thin
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -151,6 +151,20 @@ dependencies:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0.9'
154
+ - !ruby/object:Gem::Dependency
155
+ name: sigdump
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: 0.2.4
161
+ type: :runtime
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: 0.2.4
154
168
  description: generates and run a radar-app.
155
169
  email:
156
170
  - desenvolvimento@investtools.com.br
@@ -175,7 +189,9 @@ files:
175
189
  - lib/radar/app/controller.rb
176
190
  - lib/radar/app/core_ext.rb
177
191
  - lib/radar/app/core_ext/date.rb
192
+ - lib/radar/app/healthz.rb
178
193
  - lib/radar/app/logger.rb
194
+ - lib/radar/app/multiplexed_processor.rb
179
195
  - lib/radar/app/processor_factory.rb
180
196
  - lib/radar/app/runner.rb
181
197
  - lib/radar/app/server.rb
@@ -185,11 +201,13 @@ files:
185
201
  - lib/radar/app/tasks/generate.rb
186
202
  - lib/radar/app/tasks/new.rb
187
203
  - lib/radar/app/tasks/server.rb
204
+ - lib/radar/app/tasks/status.rb
188
205
  - lib/radar/app/version.rb
189
206
  - radar-app.gemspec
190
207
  - spec/lib/radar/app/analyzer_spec.rb
191
208
  - spec/lib/radar/app/processor_factory_spec.rb
192
209
  - spec/lib/radar/app/tasks/generate_spec.rb
210
+ - spec/lib/radar/app/tasks/status_spec.rb
193
211
  - templates/DOKKU_SCALE
194
212
  - templates/Gemfile
195
213
  - templates/Procfile
@@ -215,8 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
233
  - !ruby/object:Gem::Version
216
234
  version: '0'
217
235
  requirements: []
218
- rubyforge_project:
219
- rubygems_version: 2.5.1
236
+ rubygems_version: 3.0.6
220
237
  signing_key:
221
238
  specification_version: 4
222
239
  summary: radar-app generator
@@ -224,3 +241,4 @@ test_files:
224
241
  - spec/lib/radar/app/analyzer_spec.rb
225
242
  - spec/lib/radar/app/processor_factory_spec.rb
226
243
  - spec/lib/radar/app/tasks/generate_spec.rb
244
+ - spec/lib/radar/app/tasks/status_spec.rb