Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically update workers with new libraries before jobs start #2341

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ApplicationJob < ActiveJob::Base
before_perform do |job|
begin
SiteSettings.clear_cache
Library.register_all_storage
rescue
nil
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def register_storage
Shrine.storages[storage_key] = storage
end

def self.register_all_storage
find_each(&:register_storage)
rescue ActiveRecord::StatementInvalid
nil # migrations probably haven't run yet to create library table
end

private

def ensure_path_case_is_correct
Expand Down
4 changes: 1 addition & 3 deletions config/initializers/shrine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@
}

Rails.application.config.after_initialize do
Library.find_each(&:register_storage)
rescue ActiveRecord::StatementInvalid
nil # migrations probably haven't run yet to create library table
Library.register_all_storage
end
Loading