Class: PatientHttp::PayloadStore::S3Store
- Defined in:
- lib/patient_http/payload_store/s3_store.rb
Overview
S3-based payload store for production deployments.
Stores payloads as JSON objects in S3. This store is recommended for production environments where payloads need durable storage and can be shared across multiple processes/instances.
Thread-safe: S3 clients handle their own thread safety.
Instance Attribute Summary collapse
-
#key_prefix ⇒ String
readonly
The key prefix used for all stored payloads.
Instance Method Summary collapse
-
#delete(key) ⇒ Boolean
Delete a payload from S3.
-
#exists?(key) ⇒ Boolean
Check if a payload exists.
-
#fetch(key) ⇒ Hash?
Fetch data from S3.
-
#initialize(bucket:, key_prefix: nil) ⇒ S3Store
constructor
Initialize a new S3 store.
-
#store_json(key, json) ⇒ String
Store pre-serialized JSON string directly in S3.
Methods inherited from Base
create, #generate_key, lookup, register, registered_adapters, #store
Constructor Details
#initialize(bucket:, key_prefix: nil) ⇒ S3Store
Initialize a new S3 store.
35 36 37 38 39 40 |
# File 'lib/patient_http/payload_store/s3_store.rb', line 35 def initialize(bucket:, key_prefix: nil) raise ArgumentError, "S3 bucket is required" unless bucket @bucket = bucket @key_prefix = key_prefix || "patient_http/payloads/" end |
Instance Attribute Details
#key_prefix ⇒ String (readonly)
Returns The key prefix used for all stored payloads.
27 28 29 |
# File 'lib/patient_http/payload_store/s3_store.rb', line 27 def key_prefix @key_prefix end |
Instance Method Details
#delete(key) ⇒ Boolean
Delete a payload from S3.
Idempotent - does not raise if object doesn’t exist.
72 73 74 75 76 |
# File 'lib/patient_http/payload_store/s3_store.rb', line 72 def delete(key) full_key = key_with_prefix(key) @bucket.object(full_key).delete true end |
#exists?(key) ⇒ Boolean
Check if a payload exists.
82 83 84 85 |
# File 'lib/patient_http/payload_store/s3_store.rb', line 82 def exists?(key) full_key = key_with_prefix(key) @bucket.object(full_key).exists? end |
#fetch(key) ⇒ Hash?
Fetch data from S3.
57 58 59 60 61 62 63 64 |
# File 'lib/patient_http/payload_store/s3_store.rb', line 57 def fetch(key) full_key = key_with_prefix(key) response = @bucket.object(full_key).get JSON.parse(response.body.read) rescue Aws::S3::Errors::NoSuchKey nil end |
#store_json(key, json) ⇒ String
Store pre-serialized JSON string directly in S3.
47 48 49 50 51 |
# File 'lib/patient_http/payload_store/s3_store.rb', line 47 def store_json(key, json) full_key = key_with_prefix(key) @bucket.object(full_key).put(body: json, content_type: "application/json") key end |