brasa 0.5.0 → 0.5.2
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 +6 -3
- data/lib/brasa/commands/up.rb +23 -8
- 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: b01ebcbc4eb417f8b1dac15e9e4b3ecdeb95ae7a7a470097023c1392db688cef
|
|
4
|
+
data.tar.gz: 0bc8d7b38a3f71469c7d396b260a54f646c0003cb19efa8d39c4afbf80a369f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fba676de313e7587c4138475991a88e9b470aca71f938ee70e2fb3cc7271b81f7fa5929e78ab13512d93ad1c2f236a9ff64bcca91ff71401715a81bebc975ba
|
|
7
|
+
data.tar.gz: dc5b3b1d3eb17cc4e69d2d614b2817c334a9c17af8ae44eb3d18aaddf4961a2b07f9df6724e714802c39ea731d5e8b41d390491e5954528abe3bf39124371397
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "brasa/commands/base"
|
|
2
2
|
require "brasa/source_packer"
|
|
3
|
+
require "tty-spinner"
|
|
3
4
|
|
|
4
5
|
module Brasa
|
|
5
6
|
module Commands
|
|
@@ -15,11 +16,13 @@ module Brasa
|
|
|
15
16
|
info("Empacotando código...")
|
|
16
17
|
archive_path = SourcePacker.pack
|
|
17
18
|
size_kb = File.size(archive_path) / 1024
|
|
18
|
-
info("Enviando #{size_kb}KB para o servidor...")
|
|
19
19
|
|
|
20
|
+
spinner = TTY::Spinner.new("#{pastel.cyan(" Enviando #{size_kb}KB...")} :spinner", format: :dots)
|
|
21
|
+
spinner.auto_spin
|
|
20
22
|
deploy = api.upload("/api/v1/apps/#{slug}/deploys",
|
|
21
23
|
file_path: archive_path,
|
|
22
24
|
params: { branch: options["branch"] || project_config[:branch] || "main" })
|
|
25
|
+
spinner.success(pastel.green("enviado!"))
|
|
23
26
|
info("Deploy ##{deploy["id"]} criado.")
|
|
24
27
|
info(" Na fila...")
|
|
25
28
|
|
|
@@ -50,7 +53,7 @@ module Brasa
|
|
|
50
53
|
else
|
|
51
54
|
error("\nDeploy falhou.")
|
|
52
55
|
end
|
|
53
|
-
rescue Websocket::CableClient::ConnectionError => e
|
|
56
|
+
rescue Brasa::Websocket::CableClient::ConnectionError => e
|
|
54
57
|
$stderr.puts "\n [WebSocket indisponível: #{e.message}. Usando polling...]"
|
|
55
58
|
wait_for_deploy_polling(slug, deploy_id)
|
|
56
59
|
ensure
|
|
@@ -59,7 +62,7 @@ module Brasa
|
|
|
59
62
|
|
|
60
63
|
def connect_websocket
|
|
61
64
|
require "brasa/websocket/cable_client"
|
|
62
|
-
Websocket::CableClient.new.tap(&:connect!)
|
|
65
|
+
Brasa::Websocket::CableClient.new.tap(&:connect!)
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
def wait_for_deploy_polling(slug, deploy_id)
|
data/lib/brasa/commands/up.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "brasa/commands/base"
|
|
2
2
|
require "brasa/source_packer"
|
|
3
|
+
require "tty-spinner"
|
|
3
4
|
|
|
4
5
|
module Brasa
|
|
5
6
|
module Commands
|
|
@@ -79,9 +80,13 @@ module Brasa
|
|
|
79
80
|
info("Empacotando código...")
|
|
80
81
|
archive_path = SourcePacker.pack
|
|
81
82
|
size_kb = File.size(archive_path) / 1024
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
|
|
84
|
+
spinner = TTY::Spinner.new("#{pastel.cyan(" Enviando #{size_kb}KB...")} :spinner", format: :dots)
|
|
85
|
+
spinner.auto_spin
|
|
86
|
+
result = api.upload("/api/v1/apps/#{slug}/deploys", file_path: archive_path,
|
|
87
|
+
params: { branch: project_config[:branch] || "main" })
|
|
88
|
+
spinner.success(pastel.green("enviado!"))
|
|
89
|
+
result
|
|
85
90
|
ensure
|
|
86
91
|
FileUtils.rm_f(archive_path) if archive_path
|
|
87
92
|
end
|
|
@@ -100,8 +105,13 @@ module Brasa
|
|
|
100
105
|
until_status: %w[active error],
|
|
101
106
|
timeout: PROVISION_TIMEOUT)
|
|
102
107
|
|
|
103
|
-
status == "active"
|
|
104
|
-
|
|
108
|
+
if status == "active"
|
|
109
|
+
true
|
|
110
|
+
else
|
|
111
|
+
error("\nErro no provisionamento.")
|
|
112
|
+
false
|
|
113
|
+
end
|
|
114
|
+
rescue Brasa::Websocket::CableClient::ConnectionError => e
|
|
105
115
|
warn_fallback(e)
|
|
106
116
|
wait_for_provisioning_polling(slug)
|
|
107
117
|
ensure
|
|
@@ -120,8 +130,13 @@ module Brasa
|
|
|
120
130
|
until_status: %w[live failed],
|
|
121
131
|
timeout: DEPLOY_TIMEOUT)
|
|
122
132
|
|
|
123
|
-
status == "live"
|
|
124
|
-
|
|
133
|
+
if status == "live"
|
|
134
|
+
true
|
|
135
|
+
else
|
|
136
|
+
error("\nDeploy falhou.")
|
|
137
|
+
false
|
|
138
|
+
end
|
|
139
|
+
rescue Brasa::Websocket::CableClient::ConnectionError => e
|
|
125
140
|
warn_fallback(e)
|
|
126
141
|
wait_for_deploy_polling(slug, deploy_id)
|
|
127
142
|
ensure
|
|
@@ -130,7 +145,7 @@ module Brasa
|
|
|
130
145
|
|
|
131
146
|
def connect_websocket
|
|
132
147
|
require "brasa/websocket/cable_client"
|
|
133
|
-
Websocket::CableClient.new.tap(&:connect!)
|
|
148
|
+
Brasa::Websocket::CableClient.new.tap(&:connect!)
|
|
134
149
|
end
|
|
135
150
|
|
|
136
151
|
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)
|