Class: AppProfiler::Storage::GoogleCloudStorage
- Inherits:
-
BaseStorage
- Object
- BaseStorage
- AppProfiler::Storage::GoogleCloudStorage
- Defined in:
- lib/app_profiler/storage/google_cloud_storage.rb
Constant Summary collapse
- GOOGLE_SCOPE =
"https://www.googleapis.com/auth/devstorage.read_write"
Class Method Summary collapse
- .enqueue_upload(profile) ⇒ Object
-
.reset_queue ⇒ Object
for testing.
- .upload(profile, _params = {}) ⇒ Object
Class Method Details
.enqueue_upload(profile) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/app_profiler/storage/google_cloud_storage.rb', line 38 def enqueue_upload(profile) mutex.synchronize do process_queue_thread unless @process_queue_thread&.alive? @queue ||= init_queue begin @queue.push(profile, true) # non-blocking push, raises ThreadError if queue is full AppProfiler.profile_enqueue_success&.call rescue ThreadError AppProfiler.logger.info("[AppProfiler] upload queue is full, profile discarded") AppProfiler.profile_enqueue_failure&.call(profile) end end end |
.reset_queue ⇒ Object
for testing
53 54 55 56 57 |
# File 'lib/app_profiler/storage/google_cloud_storage.rb', line 53 def reset_queue # for testing init_queue @process_queue_thread&.kill @process_queue_thread = nil end |
.upload(profile, _params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/app_profiler/storage/google_cloud_storage.rb', line 15 def upload(profile, _params = {}) file = profile.file.open = if AppProfiler. && profile..present? profile. end ActiveSupport::Notifications.instrument( "gcs_upload.app_profiler", file_size: file.size, ) do bucket.create_file( StringIO.new(gzipped_reader(file).read), gcs_filename(profile), content_type: "application/json", content_encoding: "gzip", metadata: , ) ensure profile.file.unlink end end |