Streaming responses (WIP)

This commit is contained in:
2024-07-06 20:28:58 -03:00
parent 86e2db39fb
commit b611ed199b
4 changed files with 55 additions and 62 deletions

View File

@@ -47,14 +47,18 @@ module Faaso
begin
Log.info { "Uploading funko to #{FAASO_SERVER}" }
response = Crest.post(
Log.info { "Starting remote build:" }
Crest.post(
url,
{"funko.tgz" => File.open(tmp), "name" => "funko.tgz"},
user: "admin", password: "admin"
)
) do |response|
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
Log.info { "Build finished successfully." }
body = JSON.parse(response.body)
Log.info { body["output"] }
rescue ex : Crest::InternalServerError
Log.error(exception: ex) { "Error building funko #{funko.name} from #{funko.path}" }
return 1

View File

@@ -28,21 +28,27 @@ module Faaso
def remote(options, name, scale) : Int32
if !scale
response = Crest.get(
Crest.get(
"#{FAASO_SERVER}funkos/#{name}/scale/", \
user: "admin", password: "admin")
user: "admin", password: "admin") do |response|
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
else
response = Crest.post(
Crest.post(
"#{FAASO_SERVER}funkos/#{name}/scale/",
{"scale" => scale}, user: "admin", password: "admin")
{"scale" => scale}, user: "admin", password: "admin") do |response|
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
end
body = JSON.parse(response.body)
Log.info { body["output"] }
0
rescue ex : Crest::InternalServerError
Log.error { "Error scaling funko #{name}" }
body = JSON.parse(ex.response.body)
Log.info { body["output"] }
Log.error(exception: ex) { "Error scaling funko #{name}" }
1
end

View File

@@ -5,6 +5,11 @@ module Faaso
funko = Funko::Funko.from_names([name])[0]
status = funko.docker_status
if status.images.size == 0
Log.error { "Unkown funko: #{name}" }
return 1
end
Log.info { "Name: #{status.@name}" }
Log.info { "Scale: #{status.scale}" }
@@ -21,16 +26,17 @@ module Faaso
end
def remote(options, name) : Int32
response = Crest.get(
Crest.get(
"#{FAASO_SERVER}funkos/#{name}/status/", \
user: "admin", password: "admin")
body = JSON.parse(response.body)
Log.info { body["output"] }
user: "admin", password: "admin") do |response|
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
0
rescue ex : Crest::InternalServerError
Log.error { "Error scaling funko #{name}" }
body = JSON.parse(ex.response.body)
Log.info { body["output"] }
Log.error(exception: ex) { "Error scaling funko #{name}" }
1
end