Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/placeos-frontend-loader/loader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
Log = ::Log.for(self)

Habitat.create do
setting content_directory : String = WWW

Check warning on line 17 in src/placeos-frontend-loader/loader.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UselessAssign

Useless assignment to variable `content_directory`
Raw output
> setting content_directory : String = WWW
          ^
setting update_crontab : String = CRON

Check warning on line 18 in src/placeos-frontend-loader/loader.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UselessAssign

Useless assignment to variable `update_crontab`
Raw output
> setting update_crontab : String = CRON
          ^
setting max_retry_attempts : Int32 = MAX_RETRY_ATTEMPTS

Check warning on line 19 in src/placeos-frontend-loader/loader.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UselessAssign

Useless assignment to variable `max_retry_attempts`
Raw output
> setting max_retry_attempts : Int32 = MAX_RETRY_ATTEMPTS
          ^
setting max_backoff_seconds : Int32 = MAX_BACKOFF_SECONDS

Check warning on line 20 in src/placeos-frontend-loader/loader.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UselessAssign

Useless assignment to variable `max_backoff_seconds`
Raw output
> setting max_backoff_seconds : Int32 = MAX_BACKOFF_SECONDS
          ^
end

class_getter instance : Loader do
Expand Down Expand Up @@ -132,10 +132,30 @@
load_resources(timeout: LOAD_TIMEOUT).tap do
# Pull base PlaceOS WWW folder
create_base_www
# Clean up stale temp folders
cleanup_stale_temp_folders
end
end

# Remove temp folders older than 12 hours
protected def cleanup_stale_temp_folders
www_folder = File.expand_path(content_directory)
cutoff_time = Time.utc - 12.hours

stale_dirs = Dir.children(www_folder)
.select { |child| File.directory?(Path[www_folder, child]) }
.select(&.matches?(/^.+_temp_\d+$/))
.select do |dir|
path = Path[www_folder, dir]
File.info?(path).try { |info| info.modification_time < cutoff_time } || false
end

stale_dirs.each { |dir| Log.info { "removing stale temp folder: #{dir}" } }
stale_dirs.map! { |dir| Path[www_folder, dir].to_s }
FileUtils.rm_rf(stale_dirs) unless stale_dirs.empty?
end

def process_resource(action : Resource::Action, resource : Model::Repository) : Resource::Result

Check warning on line 158 in src/placeos-frontend-loader/loader.cr

View workflow job for this annotation

GitHub Actions / Ameba

Metrics/CyclomaticComplexity

Cyclomatic complexity too high [15/10]
Raw output
> def process_resource(action : Resource::Action, resource : Model::Repository) : Resource::Result
      ^
repository = resource

# Only consider Interface Repositories
Expand Down
Loading