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` # 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 # The point is for the user to remove these configuration records
# one by one as the reported problems are removed from the code base. # one by one as the reported problems are removed from the code base.
# Problems found: 2 # Problems found: 9
# 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
# Run `ameba --only Documentation/DocumentationAdmonition` for details # Run `ameba --only Documentation/DocumentationAdmonition` for details
Documentation/DocumentationAdmonition: Documentation/DocumentationAdmonition:
Description: Reports documentation admonitions Description: Reports documentation admonitions
Timezone: UTC Timezone: UTC
Excluded: Excluded:
- src/faaso.cr - src/faaso.cr
- src/funko.cr
- spec/faaso_spec.cr - spec/faaso_spec.cr
Admonitions: Admonitions:
- TODO - TODO
@ -38,49 +18,3 @@ Documentation/DocumentationAdmonition:
- BUG - BUG
Enabled: true Enabled: true
Severity: Warning 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}" container_name = "faaso-#{funko.name}"
docker_api = Docr::API.new(Docr::Client.new) docker_api = Docr::API.new(Docr::Client.new)
images = funko.image_history if funko.image_history.empty?
if images.empty?
puts "Error: no images available for #{funko.name}:latest" puts "Error: no images available for #{funko.name}:latest"
next next
end end
# sort list of funko containers newer image first case funko
containers = funko.containers.sort { |a, b| when .running?
(images.index(b.@image_id) || 9999) <=> (images.index(a.@image_id) || 9999)
}
# If it's already up, do nothing # If it's already up, do nothing
# FIXME: bring back out-of-date warning # FIXME: bring back out-of-date warning
if funko.running?
puts "#{funko.name} is already up" puts "#{funko.name} is already up"
next when .paused?
end
# If it is paused, unpause it # If it is paused, unpause it
paused = containers.select { |container|
container.@state == "paused"
}
if paused.size > 0
puts "Resuming existing paused container" puts "Resuming existing paused container"
docker_api.containers.unpause(paused[0].@id) funko.unpause
next when .exited?
end
# If it is exited, start it
existing = containers.select { |container|
container.@state == "exited"
}
puts "Starting function #{funko.name}" puts "Starting function #{funko.name}"
if existing.size > 0
puts "Restarting existing exited container" puts "Restarting existing exited container"
docker_api.containers.start(existing[0].@id) funko.start
next else
end # FIXME: move into Funko class
# Deploy from scratch # Deploy from scratch
Faaso.setup_network # We need it Faaso.setup_network # We need it
puts "Creating new container" puts "Creating new container"
@ -162,6 +142,7 @@ module Faaso
end end
end end
end end
end
class Down class Down
@arguments : Array(String) = [] of String @arguments : Array(String) = [] of String

View File

@ -59,10 +59,49 @@ class Funko
) )
end end
# Is this funko running? # Is any instance of this funko running?
def running? def running?
self.containers.any? { |container| self.containers.any? { |container|
container.@state == "running" container.@state == "running"
} }
end 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 end