wireway 202009251743 → 202009260916
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 +4 -4
- data/app/models/wireway/business_logic/restful.rb +39 -32
- data/app/models/wireway/spark.rb +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc36a1205a1ce8c38095ccac73fcff1807c07434105769785a2b7db98450ff60
|
4
|
+
data.tar.gz: f5a4cd7ecbce2efab9f053ed8fe28abc535e46ae494c81ecb2bd5ff862f4e11d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a679323899c8252c4a9d09e5d6f82b42d6e291f08d64d7af73bb495fcf67370ef5c1046d6b514d9b02cda4a22d0f75801cb32a87b3c88f6966b62340713ed59
|
7
|
+
data.tar.gz: 593a2e97789b881197610b6a737ec07afc53506d587f2ceac862e54062dcc2441b6fe67008fc2aaf8545fc61c67ca7138f9519ccb63983c9d88d41e882165292
|
@@ -12,20 +12,13 @@ module Wireway
|
|
12
12
|
return $wireway_node_addresses unless $wireway_node_addresses == 404
|
13
13
|
|
14
14
|
hosts = ['172.28.81.156:3113']
|
15
|
-
route = '/satcom/
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
result = post(addresses: hosts, route: route, params: params) do |res|
|
22
|
-
body = JSON.parse(res[1][:body]).deep_symbolize_keys
|
23
|
-
return [false, body[:result]] unless body[:success]
|
24
|
-
[true, body[:result]]
|
15
|
+
route = '/satcom/other/c919/node_addresses.json'
|
16
|
+
res = get(addresses: hosts, route: route) do |result|
|
17
|
+
hash = JSON.parse(result[1][:body]).deep_symbolize_keys
|
18
|
+
[true, hash]
|
25
19
|
end
|
26
|
-
raise
|
27
|
-
|
28
|
-
$wireway_node_addresses = result[1].map{|key, value| [key, value[:nodes]]}.to_h
|
20
|
+
raise res[1] unless res[0]
|
21
|
+
$wireway_node_addresses = res[1].map{|key, value| [key, value[:nodes]]}.to_h
|
29
22
|
end
|
30
23
|
|
31
24
|
def dashboard(**args)
|
@@ -34,9 +27,9 @@ module Wireway
|
|
34
27
|
}.merge!(args)
|
35
28
|
route = '/dashboard/restful/request_api'
|
36
29
|
|
37
|
-
post(addresses: node_addresses[:dashboard], route: route, params: params) do |
|
30
|
+
post(addresses: node_addresses[:dashboard], route: route, params: params) do |result|
|
38
31
|
return res if (params[:response_type] != 'json')
|
39
|
-
body = JSON.parse(
|
32
|
+
body = JSON.parse(result[1][:body]).deep_symbolize_keys
|
40
33
|
return [false, body[:result]] unless body[:success]
|
41
34
|
[true, body[:html_content]]
|
42
35
|
end
|
@@ -46,42 +39,56 @@ module Wireway
|
|
46
39
|
params = {}.merge!(args)
|
47
40
|
route = '/satcom/restful/request_api'
|
48
41
|
|
49
|
-
post(addresses: node_addresses[:satcom], route: route, params: params) do |
|
50
|
-
body = JSON.parse(
|
42
|
+
post(addresses: node_addresses[:satcom], route: route, params: params) do |result|
|
43
|
+
body = JSON.parse(result[1][:body]).deep_symbolize_keys
|
51
44
|
return [false, body[:result]] unless body[:success]
|
52
45
|
[true, body[:result]]
|
53
46
|
end
|
54
47
|
end
|
55
48
|
|
56
49
|
|
57
|
-
def get(
|
58
|
-
|
59
|
-
full_url = [
|
50
|
+
def get(addresses:, route:, params: {})
|
51
|
+
result = round_robin(addresses: addresses) do |address|
|
52
|
+
full_url = [address+route, URI.encode_www_form(params)]
|
60
53
|
full_url.delete_if{|item| !item.present? }
|
61
54
|
RestClient.get(full_url.join("?"))
|
62
55
|
end
|
56
|
+
return result unless (result[0] && block_given?)
|
57
|
+
|
58
|
+
begin
|
59
|
+
yield result
|
60
|
+
rescue
|
61
|
+
return [false, '运行时结果处理异常', {errors: {message: $!.to_s, path: $@}}]
|
62
|
+
end
|
63
63
|
end
|
64
64
|
|
65
65
|
def post(addresses:, route:, params: {})
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
# TODO: 后期应该优化判断是服务不可以用还是传递参数问题倒是返回false
|
72
|
-
# 或者当一定比例节点均无法正常响应时即判定为参数问题
|
73
|
-
break if res[0]
|
74
|
-
end
|
75
|
-
return res unless (block_given? || res[0])
|
76
|
-
|
66
|
+
result = round_robin(addresses: addresses) do |address|
|
67
|
+
RestClient.post "#{address}/#{route}", params
|
68
|
+
end
|
69
|
+
return result unless (result[0] && block_given?)
|
70
|
+
|
77
71
|
begin
|
78
|
-
yield
|
72
|
+
yield result
|
79
73
|
rescue
|
80
74
|
return [false, '运行时结果处理异常', {errors: {message: $!.to_s, path: $@}}]
|
81
75
|
end
|
82
76
|
end
|
83
77
|
|
84
78
|
private
|
79
|
+
def round_robin(addresses:)
|
80
|
+
res = nil
|
81
|
+
addresses.each do |address|
|
82
|
+
res = get_response do
|
83
|
+
yield address
|
84
|
+
end
|
85
|
+
# TODO: 后期应该优化判断是服务不可以用还是传递参数问题倒是返回false
|
86
|
+
# 或者当一定比例节点均无法正常响应时即判定为参数问题
|
87
|
+
break if res[0]
|
88
|
+
end
|
89
|
+
res
|
90
|
+
end
|
91
|
+
|
85
92
|
def get_response
|
86
93
|
begin
|
87
94
|
response = yield
|
data/app/models/wireway/spark.rb
CHANGED
@@ -4,9 +4,13 @@ module Wireway
|
|
4
4
|
# Wireway::Spark.dashboard(api_code: :publish_other_request_assets, rely_assets: ["bootstrap_4", "jQuery_3_5_1", "chart_js"])
|
5
5
|
# Wireway::Spark.satcom(api_code: :finance_fund_base_info, code: '161725')
|
6
6
|
def self.method_missing(method_name, **args)
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
begin
|
8
|
+
target = Wireway::BusinessLogic::Restful
|
9
|
+
return [false, '未找到相关定义方法'] unless target.respond_to?(method_name)
|
10
|
+
res = target.send(method_name, args)
|
11
|
+
rescue
|
12
|
+
return [false, '请求异常', {errors: {message: $!.to_s, path: $@}}]
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wireway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '202009260916'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ff4c00
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|