Skip to content

Commit 071f0ea

Browse files
authored
Merge pull request #11569 from demarches-simplifiees/use_active_storage_client
[Tech] Remove ConnectionPool and use activestorage client instead
2 parents 0c2bb52 + 3c56cd6 commit 071f0ea

File tree

7 files changed

+17
-35
lines changed

7 files changed

+17
-35
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ gem 'chartkick'
2424
gem 'chunky_png'
2525
gem 'clamav-client', require: 'clamav/client'
2626
gem "concurrent-ruby", "< 1.3.5" # force version to avoid https://github.com/rails/rails/pull/54264, should be removed after rails 7.2.x
27-
gem 'connection_pool'
2827
gem 'daemons'
2928
gem 'deep_cloneable' # Enable deep clone of active record models
3029
gem 'delayed_cron_job', require: false # Cron jobs

Gemfile.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,6 @@ DEPENDENCIES
996996
chunky_png
997997
clamav-client
998998
concurrent-ruby (< 1.3.5)
999-
connection_pool
1000999
daemons
10011000
deep_cloneable
10021001
delayed_cron_job

app/jobs/delayed_purge_job.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@ def delay = Integer(ENV['PURGE_LATER_DELAY_IN_DAY']).day.from_now.to_i
4848

4949
# head object to update metadata makes pj unreadable. copy with extra headers
5050
def soft_delete
51-
OpenStackStorage.with_client do |client|
52-
excon_response = client.copy_object(container, key, container, key, { "Content-Type" => blob.content_type, 'X-Delete-At' => delay.to_s })
53-
if excon_response.status != 201
54-
Sentry.capture_message("Can't expire blob", extra: { key:, headers: })
55-
else
56-
service.delete_prefixed("variants/#{key}/") if blob.image?
57-
end
51+
excon_response = client.copy_object(container, key, container, key, { "Content-Type" => blob.content_type, 'X-Delete-At' => delay.to_s })
52+
if excon_response.status != 201
53+
Sentry.capture_message("Can't expire blob", extra: { key:, headers: })
54+
else
55+
service.delete_prefixed("variants/#{key}/") if blob.image?
5856
end
5957
end
6058

@@ -63,4 +61,8 @@ def soft_delete_enabled?
6361
rescue
6462
false
6563
end
64+
65+
def client
66+
ActiveStorage::Blob.service.send(:client)
67+
end
6668
end

app/lib/active_storage/downloadable_file.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def self.cleanup_list_from_dossier(files)
2525
else
2626
service = file.blob.service
2727
begin
28-
OpenStackStorage.with_client do |client|
29-
client.head_object(service.container, file.blob.key)
30-
end
28+
client.head_object(service.container, file.blob.key)
3129
true
3230
rescue Fog::OpenStack::Storage::NotFound
3331
false
@@ -38,6 +36,10 @@ def self.cleanup_list_from_dossier(files)
3836

3937
private
4038

39+
def self.client
40+
ActiveStorage::Blob.service.send(:client)
41+
end
42+
4143
def self.bill_and_path(bill)
4244
[
4345
bill,

config/initializers/openstack_connection_pool.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

spec/jobs/delayed_purge_job_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
it 'emit request instead of destroying it' do
2020
container = "bucket"
21+
client = double("client")
2122
double_service = double(container:)
2223
allow_any_instance_of(ActiveStorage::Blob).to receive(:service).and_return(double_service)
2324

24-
allow(OpenStackStorage).to receive(:with_client).and_yield(client)
25+
allow_any_instance_of(DelayedPurgeJob).to receive(:client).and_return(client)
2526

2627
expect(client).to receive(:copy_object)
2728
.with(container, blob.key, container, blob.key, { 'X-Delete-At' => anything, "Content-Type" => blob.content_type })

spec/lib/active_storage/downloadable_file_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
require 'fog/openstack'
4545
Rails.application.config.active_storage.service = :openstack
4646

47-
allow(OpenStackStorage).to receive(:with_client).and_yield(active_storage_client)
47+
allow(ActiveStorage::DownloadableFile).to receive(:client).and_return(active_storage_client)
4848
end
4949
after { Rails.application.config.active_storage.service = :test }
5050

0 commit comments

Comments
 (0)