Add resource limits to docker-compose.yml file and fix Immich import bug

This commit is contained in:
Eugene Burmakin 2024-09-02 18:28:17 +02:00
parent 0cc5ac0860
commit 2a960826eb
10 changed files with 66 additions and 19 deletions

View file

@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.13.0] — 2024-09-02
### Added
- Resource limits to docke-compose.yml file to prevent server overload. Feel free to adjust the limits to your needs.
```yml
deploy:
resources:
limits:
cpus: '0.50' # Limit CPU usage to 50% of one core
memory: '2G' # Limit memory usage to 2GB
```
### Fixed
- Importing geodata from Immich will now not throw an error in the end of the process
## [0.12.2] — 2024-08-28
### Added

File diff suppressed because one or more lines are too long

View file

@ -12,7 +12,7 @@ class ExportsController < ApplicationController
export_name = "export_from_#{params[:start_at].to_date}_to_#{params[:end_at].to_date}"
export = current_user.exports.create(name: export_name, status: :created)
ExportJob.perform_later(export.id, params[:start_at], params[:end_at])
ExportJob.perform_later(export.id, params[:start_at], params[:end_at], format: params[:format])
redirect_to exports_url, notice: 'Export was successfully initiated. Please wait until it\'s finished.'
rescue StandardError => e

View file

@ -3,9 +3,9 @@
class ExportJob < ApplicationJob
queue_as :exports
def perform(export_id, start_at, end_at)
def perform(export_id, start_at, end_at, format: :json)
export = Export.find(export_id)
Exports::Create.new(export:, start_at:, end_at:).call
Exports::Create.new(export:, start_at:, end_at:, format:).call
end
end

View file

@ -39,7 +39,8 @@ class ExportSerializer
tst: point.timestamp.to_i,
inrids: point.inrids,
inregions: point.in_regions,
topic: point.topic
topic: point.topic,
raw_data: point.raw_data
}
end

View file

@ -1,11 +1,12 @@
# frozen_string_literal: true
class Exports::Create
def initialize(export:, start_at:, end_at:)
def initialize(export:, start_at:, end_at:, format: :json)
@export = export
@user = export.user
@start_at = start_at.to_datetime
@end_at = end_at.to_datetime
@format = format
end
def call
@ -18,7 +19,7 @@ class Exports::Create
Rails.logger.debug "====Exporting #{points.size} points"
data = ::ExportSerializer.new(points, user.email).call
file_path = Rails.root.join('public', 'exports', "#{export.name}.json")
file_path = Rails.root.join('public', 'exports', "#{export.name}.#{format}")
File.open(file_path, 'w') { |file| file.write(data) }
@ -35,7 +36,7 @@ class Exports::Create
private
attr_reader :user, :export, :start_at, :end_at
attr_reader :user, :export, :start_at, :end_at, :format
def time_framed_points
user
@ -60,4 +61,10 @@ class Exports::Create
content: "Export \"#{export.name}\" failed: #{error.message}, stacktrace: #{error.backtrace.join("\n")}"
).call
end
def process_json_export(points)
end
def process_gpx_export(points)
end
end

View file

@ -13,12 +13,15 @@ class Immich::ImportGeodata
raise ArgumentError, 'Immich API key is missing' if immich_api_key.blank?
raise ArgumentError, 'Immich URL is missing' if user.settings['immich_url'].blank?
immich_data = retrieve_immich_data
immich_data = retrieve_immich_data
file = File.open('tmp/imports/immich_data.json', 'w')
file.write(immich_data)
file.close
immich_data_json = parse_immich_data(immich_data)
file_name = file_name(immich_data_json)
import = user.imports.find_or_initialize_by(name: file_name, source: :immich_api)
create_import_failed_notification and return unless import.new_record?
create_import_failed_notification(import.name) and return unless import.new_record?
import.raw_data = immich_data_json
import.save!
@ -84,12 +87,12 @@ class Immich::ImportGeodata
Rails.logger.debug 'No data found'
end
def create_import_failed_notification
def create_import_failed_notification(import_name)
Notifications::Create.new(
user:,
kind: :info,
title: 'Import was not created',
content: 'Import with the same name already exists. If you want to proceed, delete the existing import and try again.'
content: "Import with the same name (#{import_name}) already exists. If you want to proceed, delete the existing import and try again."
).call
end

View file

@ -11,6 +11,8 @@ class Immich::ImportParser
def call
json.each { |point| create_point(point) }
{ raw_points: 0, points: 0, doubles: 0, processed: 0 }
end
def create_point(point)

View file

@ -3,28 +3,33 @@
<div class="w-full">
<%= form_with url: points_path, method: :get do |f| %>
<div class="flex flex-col md:flex-row md:space-x-4 md:items-end">
<div class="w-full md:w-2/6">
<div class="w-full md:w-3/12">
<div class="flex flex-col space-y-2">
<%= f.label :start_at, class: "text-sm font-semibold" %>
<%= f.datetime_local_field :start_at, class: "rounded-md w-full", value: @start_at %>
</div>
</div>
<div class="w-full md:w-2/6">
<div class="w-full md:w-3/12">
<div class="flex flex-col space-y-2">
<%= f.label :end_at, class: "text-sm font-semibold" %>
<%= f.datetime_local_field :end_at, class: "rounded-md w-full", value: @end_at %>
</div>
</div>
<div class="w-full md:w-2/6">
<div class="w-full md:w-1/12">
<div class="flex flex-col space-y-2">
<%= f.submit "Search", class: "px-4 py-2 bg-blue-500 text-white rounded-md" %>
</div>
</div>
<div class="w-full md:w-2/6">
<div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2 text-center">
<%= link_to 'Export points', exports_path(start_at: @start_at, end_at: @end_at), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points withing timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md" %>
<%= link_to 'Export points', exports_path(start_at: @start_at, end_at: @end_at), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points withing timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md join-item" %>
</div>
</div>
<%# <div class="w-full md:w-2/12"> %>
<%# <div class="flex flex-col space-y-2 text-center"> %>
<%# <%= link_to 'Export as GPX', exports_path(start_at: @start_at, end_at: @end_at, format: :gpx), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure? This will start background process of exporting points withing timeframe, selected between #{@start_at} and #{@end_at}", turbo_method: :post }, class: "px-4 py-2 bg-green-500 text-white rounded-md join-item" %>
<%# </div> %>
<%# </div> %>
</div>
<% end %>

View file

@ -57,6 +57,11 @@ services:
depends_on:
- dawarich_db
- dawarich_redis
deploy:
resources:
limits:
cpus: '0.50' # Limit CPU usage to 50% of one core
memory: '2G' # Limit memory usage to 2GB
dawarich_sidekiq:
image: freikin/dawarich:latest
container_name: dawarich_sidekiq
@ -90,6 +95,11 @@ services:
- dawarich_db
- dawarich_redis
- dawarich_app
deploy:
resources:
limits:
cpus: '0.50' # Limit CPU usage to 50% of one core
memory: '2G' # Limit memory usage to 2GB
volumes:
db_data: