Class: QueryGuard::Uploader::UploadService
- Inherits:
-
Object
- Object
- QueryGuard::Uploader::UploadService
- Defined in:
- lib/query_guard/uploader/upload_service.rb
Overview
Service for uploading analysis reports.
This is the main public API for uploading reports. It:
- Coordinates with configured uploader
- Handles errors gracefully
- Provides logging/status information
- Never blocks or raises exceptions
Usage:
service = QueryGuard::Uploader::UploadService.new(config)
result = service.upload_report(json_string, trace_id: '...')
puts result.to_h if result.failed?
Instance Method Summary collapse
-
#initialize(config = nil) ⇒ UploadService
constructor
A new instance of UploadService.
-
#ready? ⇒ Boolean
Check if uploader is ready and configured.
-
#reconfigure(config) ⇒ self
Reconfigure with a new config object.
-
#status ⇒ Hash
Get status information about the current uploader.
-
#upload_report(json_report, trace_id: nil, request_id: nil) ⇒ UploadResult
Upload a JSON report from the configured JSON reporter.
-
#uploader ⇒ Interface
Get the current uploader instance.
Constructor Details
#initialize(config = nil) ⇒ UploadService
Returns a new instance of UploadService.
18 19 20 21 |
# File 'lib/query_guard/uploader/upload_service.rb', line 18 def initialize(config = nil) @config = config || QueryGuard.config @uploader = Registry.for_config(@config) end |
Instance Method Details
#ready? ⇒ Boolean
Check if uploader is ready and configured.
58 59 60 |
# File 'lib/query_guard/uploader/upload_service.rb', line 58 def ready? @uploader.ready? end |
#reconfigure(config) ⇒ self
Reconfigure with a new config object.
73 74 75 76 77 |
# File 'lib/query_guard/uploader/upload_service.rb', line 73 def reconfigure(config) @config = config @uploader = Registry.for_config(@config) self end |
#status ⇒ Hash
Get status information about the current uploader.
47 48 49 50 51 52 53 |
# File 'lib/query_guard/uploader/upload_service.rb', line 47 def status { uploader: @uploader.name, ready: @uploader.ready?, details: @uploader.status } end |
#upload_report(json_report, trace_id: nil, request_id: nil) ⇒ UploadResult
Upload a JSON report from the configured JSON reporter.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/query_guard/uploader/upload_service.rb', line 29 def upload_report(json_report, trace_id: nil, request_id: nil) = {} [:trace_id] = trace_id if trace_id [:request_id] = request_id if request_id @uploader.upload(json_report, ) rescue StandardError => e # Always return graceful result, never raise UploadResult.new( success: false, uploader_name: @uploader.name, error: "Unexpected error: #{e.message}" ) end |
#uploader ⇒ Interface
Get the current uploader instance.
65 66 67 |
# File 'lib/query_guard/uploader/upload_service.rb', line 65 def uploader @uploader end |