radar-app 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/radar-app +3 -1
- data/lib/radar/app.rb +23 -6
- data/lib/radar/app/analyzer_controller.rb +20 -39
- data/lib/radar/app/controller.rb +14 -10
- data/lib/radar/app/logger.rb +9 -0
- data/lib/radar/app/server.rb +3 -4
- data/lib/radar/app/session.rb +9 -0
- data/lib/radar/app/version.rb +1 -1
- data/radar-app.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 147df08f16b84c45254f8accad18b34b9b7d51f7
|
4
|
+
data.tar.gz: 6a6a25aa283d0fdd57013266091e494fedc599c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33958d283b8d2a5fa3f6a2d1618920f0425c6b91d8c72ed84dc5dc77e93a2c4c470ed2efe046a89f1978fefb02cc88b137b125f350644429b4b47d774b9a890b
|
7
|
+
data.tar.gz: 35233077784098839247952548484f0ee9dc33495018a49fba45c74360d0d63595dd5ab02643a39dc9c8db1cdb0df6a625122404754f6ea7bfe9ce89bbfe880f
|
data/bin/radar-app
CHANGED
@@ -42,9 +42,11 @@ class RadarApp < Thor
|
|
42
42
|
desc 'server', 'Starts the app server'
|
43
43
|
method_option :aliases => 's'
|
44
44
|
def server
|
45
|
+
require 'radar-app'
|
45
46
|
require 'active_support/dependencies'
|
47
|
+
require 'active_support/descendants_tracker'
|
46
48
|
ActiveSupport::Dependencies.autoload_paths << './analyzers'
|
47
|
-
require './
|
49
|
+
require './config/app.rb'
|
48
50
|
Radar::App::Server.start
|
49
51
|
end
|
50
52
|
|
data/lib/radar/app.rb
CHANGED
@@ -1,14 +1,30 @@
|
|
1
1
|
require 'radar/app/version'
|
2
2
|
require 'radar/app/core_ext'
|
3
|
+
require 'radar/app/logger'
|
4
|
+
require 'radar/app/session'
|
3
5
|
require 'radar/app/controller'
|
4
6
|
require 'radar/app/analyzer_controller'
|
5
7
|
require 'radar/app/server'
|
6
8
|
|
7
|
-
require 'connection_pool'
|
8
9
|
require 'radar-api'
|
10
|
+
require 'connection_pool'
|
11
|
+
require 'thrift_client'
|
12
|
+
require 'active_support/string_inquirer'
|
9
13
|
|
10
14
|
module Radar
|
11
15
|
module App
|
16
|
+
def self.logger=(logger)
|
17
|
+
@logger = logger
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.logger
|
21
|
+
@logger ||= ::Logger.new(STDERR)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.env
|
25
|
+
@env ||= ActiveSupport::StringInquirer.new(ENV['RADAR_ENV'] || 'development')
|
26
|
+
end
|
27
|
+
|
12
28
|
def self.security_service
|
13
29
|
@security_service ||= connection_pool(Radar::API::SecurityService::Client, 9790)
|
14
30
|
end
|
@@ -28,11 +44,12 @@ module Radar
|
|
28
44
|
end
|
29
45
|
|
30
46
|
def self.connection(client_class, port)
|
31
|
-
host
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
47
|
+
ThriftClient.new(client_class, "#{host}:#{port}",
|
48
|
+
protocol: Thrift::BinaryProtocolAccelerated, retries: 1, server_retry_period: 0)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.host
|
52
|
+
ENV['DATA_SERVER_HOST'] || '127.0.0.1'
|
36
53
|
end
|
37
54
|
end
|
38
55
|
end
|
@@ -2,68 +2,49 @@ module Radar
|
|
2
2
|
module App
|
3
3
|
class AnalyzerController
|
4
4
|
include Radar::App::Controller
|
5
|
-
attr_reader :sessions
|
6
5
|
|
7
|
-
forward :on_each_month, :on_each_day, :on_finish,
|
6
|
+
forward :on_each_month, :on_each_day, :on_finish,
|
7
|
+
:on_cash_flow, :dump, :resume, :result
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@sessions = {}
|
11
11
|
end
|
12
12
|
|
13
13
|
def analyzers
|
14
|
-
|
15
|
-
@@analyzers.values.map { |analyzer_class| analyzer_class.new.config }
|
16
|
-
end
|
14
|
+
registry.values.map { |analyzer_class| Object.const_get(analyzer_class).new.config }
|
17
15
|
end
|
18
16
|
|
19
|
-
def self
|
20
|
-
|
17
|
+
def self.<<(analyzer_class)
|
18
|
+
registry[analyzer_class.new.config.id] = analyzer_class.name
|
21
19
|
end
|
22
20
|
|
23
21
|
def create_session(session_id, analyzer_id)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
analyzer.config
|
28
|
-
end
|
22
|
+
analyzer = create_fresh_analyzer(analyzer_id)
|
23
|
+
@sessions[session_id] = Session.new(analyzer)
|
24
|
+
analyzer.config
|
29
25
|
end
|
30
26
|
|
31
|
-
def
|
32
|
-
|
33
|
-
@sessions[session_id].
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def resume(session_id, data)
|
38
|
-
handle_error do
|
39
|
-
@sessions[session_id].resume(data)
|
27
|
+
def example_result(session_id)
|
28
|
+
synchronized(session_id) do
|
29
|
+
@sessions[session_id].analyzer.example_result
|
40
30
|
end
|
41
31
|
end
|
42
32
|
|
43
|
-
|
44
|
-
handle_error do
|
45
|
-
@sessions[session_id].result
|
46
|
-
end
|
47
|
-
end
|
33
|
+
protected
|
48
34
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
35
|
+
def create_fresh_analyzer(analyzer_id)
|
36
|
+
if Radar::App.env.development?
|
37
|
+
$class_reloader.execute_if_updated
|
52
38
|
end
|
39
|
+
Object.const_get(registry[analyzer_id]).new
|
53
40
|
end
|
54
41
|
|
55
|
-
def
|
56
|
-
|
57
|
-
@sessions[session_id].example_result
|
58
|
-
end
|
42
|
+
def registry
|
43
|
+
self.class.registry
|
59
44
|
end
|
60
45
|
|
61
|
-
|
62
|
-
|
63
|
-
def create_fresh_analyzer(class_name)
|
64
|
-
ActiveSupport::DescendantsTracker.clear
|
65
|
-
ActiveSupport::Dependencies.clear
|
66
|
-
Object.const_get(class_name).new
|
46
|
+
def self.registry
|
47
|
+
(@@registry ||= {})
|
67
48
|
end
|
68
49
|
end
|
69
50
|
end
|
data/lib/radar/app/controller.rb
CHANGED
@@ -5,6 +5,14 @@ module Radar
|
|
5
5
|
module Controller
|
6
6
|
|
7
7
|
extend ActiveSupport::Concern
|
8
|
+
include Radar::App::Logger
|
9
|
+
attr_reader :sessions
|
10
|
+
|
11
|
+
def destroy_session(session_id)
|
12
|
+
synchronized(session_id) do
|
13
|
+
@sessions.delete(session_id)
|
14
|
+
end
|
15
|
+
end
|
8
16
|
|
9
17
|
module ClassMethods
|
10
18
|
|
@@ -13,8 +21,9 @@ module Radar
|
|
13
21
|
def forward(*methods)
|
14
22
|
methods.each do |method|
|
15
23
|
define_method(method) do |session_id, *args|
|
16
|
-
|
17
|
-
|
24
|
+
synchronized(session_id) do
|
25
|
+
logger.debug { "[#{session_id}] #{method}(...)" }
|
26
|
+
@sessions[session_id].analyzer.send(method, *args)
|
18
27
|
end
|
19
28
|
end
|
20
29
|
end
|
@@ -23,15 +32,10 @@ module Radar
|
|
23
32
|
|
24
33
|
protected
|
25
34
|
|
26
|
-
def
|
27
|
-
|
28
|
-
yield
|
29
|
-
rescue => e
|
30
|
-
$stderr.puts "#{e.class}: #{e.message}"
|
31
|
-
$stderr.puts e.backtrace
|
32
|
-
$stderr.puts
|
33
|
-
end
|
35
|
+
def synchronized(session_id)
|
36
|
+
@sessions[session_id].mutex.synchronize { yield }
|
34
37
|
end
|
38
|
+
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
data/lib/radar/app/server.rb
CHANGED
@@ -8,10 +8,9 @@ module Radar
|
|
8
8
|
handler = Radar::App::AnalyzerController.new
|
9
9
|
processor = Radar::API::AnalyzerController::Processor.new(handler)
|
10
10
|
transport = Thrift::ServerSocket.new(port)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
server.serve()
|
11
|
+
server = Thrift::NonblockingServer.new(processor, transport, Thrift::FramedTransportFactory.new)
|
12
|
+
$stderr.puts "Starting app on port #{port}..."
|
13
|
+
server.serve
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
data/lib/radar/app/version.rb
CHANGED
data/radar-app.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radar-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonardo Mendonca
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '4.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: thrift_client
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.9'
|
111
125
|
description: generates and run a radar-app.
|
112
126
|
email:
|
113
127
|
- leonardo.mendonca@investtools.com.br
|
@@ -129,7 +143,9 @@ files:
|
|
129
143
|
- lib/radar/app/controller.rb
|
130
144
|
- lib/radar/app/core_ext.rb
|
131
145
|
- lib/radar/app/core_ext/date.rb
|
146
|
+
- lib/radar/app/logger.rb
|
132
147
|
- lib/radar/app/server.rb
|
148
|
+
- lib/radar/app/session.rb
|
133
149
|
- lib/radar/app/version.rb
|
134
150
|
- radar-app.gemspec
|
135
151
|
- templates/Gemfile
|