Refactor, update ameba config to ignore TODO/FIXME

This commit is contained in:
Roberto Alsina 2024-06-30 00:32:31 -03:00
parent c1308c3a36
commit 08930b9ee5
3 changed files with 87 additions and 133 deletions

View File

@ -1,36 +1,16 @@
# This configuration file was generated by `ameba --gen-config`
# on 2024-06-28 23:57:47 UTC using Ameba version 1.6.1.
# on 2024-06-30 03:32:11 UTC using Ameba version 1.6.1.
# The point is for the user to remove these configuration records
# one by one as the reported problems are removed from the code base.
# Problems found: 2
# Run `ameba --only Layout/TrailingBlankLines` for details
Layout/TrailingBlankLines:
Description: Disallows trailing blank lines
Excluded:
- tmp/d1808c39-8dff-4267-9bec-6961ec16c41f/function.cr
- tmp/26456ab0-43e4-44fb-8b6f-986880ff5a41/function.cr
Enabled: true
Severity: Convention
# Problems found: 2
# Run `ameba --only Lint/Formatting` for details
Lint/Formatting:
Description: Reports not formatted sources
FailOnError: false
Excluded:
- tmp/d1808c39-8dff-4267-9bec-6961ec16c41f/function.cr
- tmp/26456ab0-43e4-44fb-8b6f-986880ff5a41/function.cr
Enabled: true
Severity: Warning
# Problems found: 13
# Problems found: 9
# Run `ameba --only Documentation/DocumentationAdmonition` for details
Documentation/DocumentationAdmonition:
Description: Reports documentation admonitions
Timezone: UTC
Excluded:
- src/faaso.cr
- src/funko.cr
- spec/faaso_spec.cr
Admonitions:
- TODO
@ -38,49 +18,3 @@ Documentation/DocumentationAdmonition:
- BUG
Enabled: true
Severity: Warning
# Problems found: 1
# Run `ameba --only Lint/DebugCalls` for details
Lint/DebugCalls:
Description: Disallows debug-related calls
Excluded:
- src/faaso.cr
MethodNames:
- p
- p!
- pp
- pp!
Enabled: true
Severity: Warning
# Problems found: 3
# Run `ameba --only Naming/BlockParameterName` for details
Naming/BlockParameterName:
Description: Disallows non-descriptive block parameter names
MinNameLength: 3
AllowNamesEndingInNumbers: true
Excluded:
- src/faaso.cr
AllowedNames:
- _
- e
- i
- j
- k
- v
- x
- y
- ex
- io
- ws
- op
- tx
- id
- ip
- k1
- k2
- v1
- v2
ForbiddenNames: []
Enabled: true
Severity: Convention

View File

@ -85,46 +85,26 @@ module Faaso
container_name = "faaso-#{funko.name}"
docker_api = Docr::API.new(Docr::Client.new)
images = funko.image_history
if images.empty?
if funko.image_history.empty?
puts "Error: no images available for #{funko.name}:latest"
next
end
# sort list of funko containers newer image first
containers = funko.containers.sort { |a, b|
(images.index(b.@image_id) || 9999) <=> (images.index(a.@image_id) || 9999)
}
case funko
when .running?
# If it's already up, do nothing
# FIXME: bring back out-of-date warning
if funko.running?
puts "#{funko.name} is already up"
next
end
when .paused?
# If it is paused, unpause it
paused = containers.select { |container|
container.@state == "paused"
}
if paused.size > 0
puts "Resuming existing paused container"
docker_api.containers.unpause(paused[0].@id)
next
end
# If it is exited, start it
existing = containers.select { |container|
container.@state == "exited"
}
funko.unpause
when .exited?
puts "Starting function #{funko.name}"
if existing.size > 0
puts "Restarting existing exited container"
docker_api.containers.start(existing[0].@id)
next
end
funko.start
else
# FIXME: move into Funko class
# Deploy from scratch
Faaso.setup_network # We need it
puts "Creating new container"
@ -162,6 +142,7 @@ module Faaso
end
end
end
end
class Down
@arguments : Array(String) = [] of String

View File

@ -59,10 +59,49 @@ class Funko
)
end
# Is this funko running?
# Is any instance of this funko running?
def running?
self.containers.any? { |container|
container.@state == "running"
}
end
# Is any instance of this funko paused?
def paused?
self.containers.any? { |container|
container.@state == "paused"
}
end
# Unpause paused container with the newer image
def unpause
docker_api = Docr::API.new(Docr::Client.new)
images = self.image_history
paused = self.containers.select { |container|
container.@state == "paused"
}.sort! { |i, j|
(images.index(j.@image_id) || 9999) <=> (images.index(i.@image_id) || 9999)
}
docker_api.containers.unpause(paused[0].@id) unless paused.empty?
end
# Is any instance of this funko exited?
def exited?
self.containers.any? { |container|
container.@state == "exited"
}
end
# Restart exited container with the newer image
def start
# FIXME refactor DRY with unpause
docker_api = Docr::API.new(Docr::Client.new)
images = self.image_history
exited = self.containers.select { |container|
container.@state == "exited"
}.sort! { |i, j|
(images.index(j.@image_id) || 9999) <=> (images.index(i.@image_id) || 9999)
}
docker_api.containers.restart(exited[0].@id) unless exited.empty?
end
end