Merge branch 'develop' into feat/add-context-to-exception

This commit is contained in:
Shivam Mishra
2026-06-23 12:05:07 +05:30
committed by GitHub
268 changed files with 10059 additions and 7602 deletions
+52
View File
@@ -0,0 +1,52 @@
require 'yaml'
require 'erb'
class ActiveStorage::Migrator
def self.migrate(from_service_name, to_service_name, should_update_service_name: true)
configs = load_storage_config
# Check if services are configured correctly
if configs[from_service_name.to_s].nil? || configs[to_service_name.to_s].nil?
raise "Error: The services '#{from_service_name}' or '#{to_service_name}' are not configured correctly."
end
from_service = configure_service(from_service_name, configs)
configure_blob_service(from_service)
migrate_blobs(from_service_name, to_service_name, should_update_service_name: should_update_service_name)
end
def self.load_storage_config
yaml_with_env = ERB.new(File.read('config/storage.yml')).result
YAML.load(yaml_with_env)
end
def self.configure_blob_service(service)
ActiveStorage::Blob.service = service
end
def self.configure_service(service_name, configs = load_storage_config)
service_config = configs[service_name.to_s]
ActiveStorage::Service.configure(service_name, { service_name.to_sym => service_config })
end
def self.migrate_blobs(from_service_name, to_service_name, should_update_service_name: true)
to_service = configure_service(to_service_name)
blobs = ActiveStorage::Blob.where(service_name: from_service_name.to_s)
Rails.logger.debug { "#{blobs.count} Blobs to migrate from #{from_service_name} to #{to_service_name}" }
blobs.find_each do |blob|
Rails.logger.debug { '.' }
blob.open do |io|
checksum = blob.checksum
to_service.upload(blob.key, io, checksum: checksum)
end
blob.update!(service_name: to_service_name.to_s) if should_update_service_name
rescue ActiveStorage::FileNotFoundError => e
Rails.logger.warn { "Skipping missing blob #{blob.id} (#{blob.key}): #{e.message}" }
end
Rails.logger.debug { 'Successful migration' }
end
end
+2
View File
@@ -2,6 +2,8 @@ module Redis::RedisKeys
## Inbox Keys
# Array storing the ordered ids for agent round robin assignment
ROUND_ROBIN_AGENTS = 'ROUND_ROBIN_AGENTS:%<inbox_id>d'.freeze
# Track recently deleted IMAP messages to prevent them from being synced again
IMAP_DELETED_MESSAGE = 'IMAP_DELETED_MESSAGE::%<inbox_id>d::%<message_id_digest>s'.freeze
## Conversation keys
# Detect whether to send an email reply to the conversation
+13
View File
@@ -0,0 +1,13 @@
namespace :storage do
desc 'Migrate blobs from one storage service to another'
# Example: FROM=local TO=amazon UPDATE_BLOB_SERVICE_NAME=true bundle exec rake storage:migrate
task migrate: :environment do
from_service = ENV.fetch('FROM', nil)
to_service = ENV.fetch('TO', nil)
should_update_service_name = ActiveModel::Type::Boolean.new.cast(ENV.fetch('UPDATE_BLOB_SERVICE_NAME', true))
raise 'Missing FROM or TO argument. Usage: FROM=service_name TO=service_name rake storage:migrate' if from_service.nil? || to_service.nil?
ActiveStorage::Migrator.migrate(from_service.to_sym, to_service.to_sym, should_update_service_name: should_update_service_name)
end
end