brasa 0.5.0 → 0.5.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 +4 -4
- data/lib/brasa/commands/deploy.rb +2 -2
- data/lib/brasa/commands/up.rb +15 -5
- data/lib/brasa/version.rb +1 -1
- data/lib/brasa/websocket/cable_client.rb +30 -7
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f58d1ef47800a723afab0a3b260562f7704a4b72e0ac364471a0dcc2b0445078
|
|
4
|
+
data.tar.gz: c1c9063b7c415605ab60e4bf2deb7274e6780c4bcf7ed7ad755b609c24d2c845
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60d66b1edd7299319e0ae56964e9b1595a18f7c49879aca09bdf02f5d023d256a31d3ce0d75719964fef60dfcbc55517497fb715ee2c778feacf3648b118742b
|
|
7
|
+
data.tar.gz: 10b6eed8ee2bf1236e28c83ab98d0d4151da0d3a59bb6efcfb01af585f92a24339a1a53bd7f7e01f5dfc24d7ef9a718e84b19211afda4e3425d5cd39c3ae7b9a
|
|
@@ -50,7 +50,7 @@ module Brasa
|
|
|
50
50
|
else
|
|
51
51
|
error("\nDeploy falhou.")
|
|
52
52
|
end
|
|
53
|
-
rescue Websocket::CableClient::ConnectionError => e
|
|
53
|
+
rescue Brasa::Websocket::CableClient::ConnectionError => e
|
|
54
54
|
$stderr.puts "\n [WebSocket indisponível: #{e.message}. Usando polling...]"
|
|
55
55
|
wait_for_deploy_polling(slug, deploy_id)
|
|
56
56
|
ensure
|
|
@@ -59,7 +59,7 @@ module Brasa
|
|
|
59
59
|
|
|
60
60
|
def connect_websocket
|
|
61
61
|
require "brasa/websocket/cable_client"
|
|
62
|
-
Websocket::CableClient.new.tap(&:connect!)
|
|
62
|
+
Brasa::Websocket::CableClient.new.tap(&:connect!)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def wait_for_deploy_polling(slug, deploy_id)
|
data/lib/brasa/commands/up.rb
CHANGED
|
@@ -100,8 +100,13 @@ module Brasa
|
|
|
100
100
|
until_status: %w[active error],
|
|
101
101
|
timeout: PROVISION_TIMEOUT)
|
|
102
102
|
|
|
103
|
-
status == "active"
|
|
104
|
-
|
|
103
|
+
if status == "active"
|
|
104
|
+
true
|
|
105
|
+
else
|
|
106
|
+
error("\nErro no provisionamento.")
|
|
107
|
+
false
|
|
108
|
+
end
|
|
109
|
+
rescue Brasa::Websocket::CableClient::ConnectionError => e
|
|
105
110
|
warn_fallback(e)
|
|
106
111
|
wait_for_provisioning_polling(slug)
|
|
107
112
|
ensure
|
|
@@ -120,8 +125,13 @@ module Brasa
|
|
|
120
125
|
until_status: %w[live failed],
|
|
121
126
|
timeout: DEPLOY_TIMEOUT)
|
|
122
127
|
|
|
123
|
-
status == "live"
|
|
124
|
-
|
|
128
|
+
if status == "live"
|
|
129
|
+
true
|
|
130
|
+
else
|
|
131
|
+
error("\nDeploy falhou.")
|
|
132
|
+
false
|
|
133
|
+
end
|
|
134
|
+
rescue Brasa::Websocket::CableClient::ConnectionError => e
|
|
125
135
|
warn_fallback(e)
|
|
126
136
|
wait_for_deploy_polling(slug, deploy_id)
|
|
127
137
|
ensure
|
|
@@ -130,7 +140,7 @@ module Brasa
|
|
|
130
140
|
|
|
131
141
|
def connect_websocket
|
|
132
142
|
require "brasa/websocket/cable_client"
|
|
133
|
-
Websocket::CableClient.new.tap(&:connect!)
|
|
143
|
+
Brasa::Websocket::CableClient.new.tap(&:connect!)
|
|
134
144
|
end
|
|
135
145
|
|
|
136
146
|
def warn_fallback(err)
|
data/lib/brasa/version.rb
CHANGED
|
@@ -17,7 +17,7 @@ module Brasa
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def connect!
|
|
20
|
-
raise ConnectionError, "
|
|
20
|
+
raise ConnectionError, "Token nao encontrado. Execute `brasa login`." unless @token
|
|
21
21
|
|
|
22
22
|
ws_url = @api_url.sub(%r{^https?://}, "wss://").chomp("/") + "/cable"
|
|
23
23
|
@ws = WebSocket::Client::Simple.connect(ws_url, headers: {
|
|
@@ -47,8 +47,14 @@ module Brasa
|
|
|
47
47
|
deadline = Time.now + timeout
|
|
48
48
|
loop do
|
|
49
49
|
return result if result
|
|
50
|
-
raise ConnectionError, "Timeout (#{timeout}s)" if Time.now > deadline
|
|
51
|
-
|
|
50
|
+
raise ConnectionError, "Timeout aguardando status (#{timeout}s)" if Time.now > deadline
|
|
51
|
+
|
|
52
|
+
unless @connected
|
|
53
|
+
reconnect!
|
|
54
|
+
# Re-subscribe after reconnect
|
|
55
|
+
@subscriptions.each_key { |id| send_command("subscribe", id) }
|
|
56
|
+
end
|
|
57
|
+
|
|
52
58
|
sleep 0.2
|
|
53
59
|
end
|
|
54
60
|
ensure
|
|
@@ -70,8 +76,12 @@ module Brasa
|
|
|
70
76
|
client = self
|
|
71
77
|
|
|
72
78
|
@ws.on :message do |msg|
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
begin
|
|
80
|
+
data = JSON.parse(msg.data)
|
|
81
|
+
client.send(:handle_message, data)
|
|
82
|
+
rescue JSON::ParserError
|
|
83
|
+
$stderr.puts "[WS] Mensagem malformada ignorada: #{msg.data.to_s.truncate(100)}" if ENV["BRASA_DEBUG"]
|
|
84
|
+
end
|
|
75
85
|
end
|
|
76
86
|
|
|
77
87
|
@ws.on :close do |_|
|
|
@@ -92,7 +102,7 @@ module Brasa
|
|
|
92
102
|
when "confirm_subscription"
|
|
93
103
|
# confirmed
|
|
94
104
|
when "reject_subscription"
|
|
95
|
-
|
|
105
|
+
@connected = false
|
|
96
106
|
else
|
|
97
107
|
identifier = data["identifier"]
|
|
98
108
|
message = data["message"]
|
|
@@ -109,11 +119,24 @@ module Brasa
|
|
|
109
119
|
deadline = Time.now + 10
|
|
110
120
|
loop do
|
|
111
121
|
return if @connected
|
|
112
|
-
raise ConnectionError, "
|
|
122
|
+
raise ConnectionError, "Timeout na conexao WebSocket" if Time.now > deadline
|
|
113
123
|
sleep 0.1
|
|
114
124
|
end
|
|
115
125
|
end
|
|
116
126
|
|
|
127
|
+
def reconnect!
|
|
128
|
+
RECONNECT_DELAYS.each do |delay|
|
|
129
|
+
sleep delay
|
|
130
|
+
begin
|
|
131
|
+
connect!
|
|
132
|
+
return
|
|
133
|
+
rescue StandardError
|
|
134
|
+
next
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
raise ConnectionError, "Falha na reconexao apos #{RECONNECT_DELAYS.size} tentativas"
|
|
138
|
+
end
|
|
139
|
+
|
|
117
140
|
def send_command(command, identifier)
|
|
118
141
|
return unless @ws&.open?
|
|
119
142
|
@ws.send({ command: command, identifier: identifier }.to_json)
|