Class: Temporalio::Contrib::Aws::S3Driver::S3StorageDriver
- Inherits:
-
Temporalio::Converters::StorageDriver
- Object
- Temporalio::Converters::StorageDriver
- Temporalio::Contrib::Aws::S3Driver::S3StorageDriver
- Defined in:
- lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb
Overview
WARNING: This API is experimental and may change in the future.
Storage driver that stores and retrieves payloads in Amazon S3.
Payloads are content addressed by a SHA-256 hash of their serialized bytes, so storing the same payload twice for the same execution uploads it once. Object keys are built from the namespace and the workflow or activity the payload is stored for, percent-encoded to S3's safe character set.
Constant Summary collapse
- DRIVER_TYPE =
Driver type shared by every S3 driver instance across SDK languages.
'aws.s3driver'- DEFAULT_MAX_PAYLOAD_SIZE =
Default maximum serialized payload size, in bytes.
50 * 1024 * 1024
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Driver instance name.
Instance Method Summary collapse
-
#initialize(client:, bucket:, driver_name: DRIVER_TYPE, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE) ⇒ S3StorageDriver
constructor
Create an S3 storage driver.
-
#retrieve(context, claims) ⇒ Array<Api::Common::V1::Payload>
Retrieve the payloads for the given claims.
-
#store(context, payloads) ⇒ Array<StorageDriverClaim>
Store the given payloads.
-
#type ⇒ String
Always DRIVER_TYPE.
Constructor Details
#initialize(client:, bucket:, driver_name: DRIVER_TYPE, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE) ⇒ S3StorageDriver
Create an S3 storage driver.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb', line 53 def initialize(client:, bucket:, driver_name: DRIVER_TYPE, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE) super() unless max_payload_size.is_a?(Integer) && max_payload_size.positive? raise ArgumentError, "max_payload_size must be a positive integer, got #{max_payload_size.inspect}" end @client = client @bucket = bucket.is_a?(String) ? proc { bucket } : bucket @name = driver_name @max_payload_size = max_payload_size end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns Driver instance name.
41 42 43 |
# File 'lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb', line 41 def name @name end |
Instance Method Details
#retrieve(context, claims) ⇒ Array<Api::Common::V1::Payload>
Retrieve the payloads for the given claims.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb', line 94 def retrieve(context, claims) claims.each { |claim| validate_claim(claim) } run_concurrently(claims.to_a, context.cancellation) do |claim, cancellation| bucket = claim.claim_data.fetch(CLAIM_BUCKET) key = claim.claim_data.fetch(CLAIM_KEY) expected_hash = claim.claim_data.fetch(CLAIM_HASH_VALUE) data = context.limiter.permit(claim) do cancellation.check! download(bucket, key) end actual_hash = Digest::SHA256.hexdigest(data) if actual_hash != expected_hash raise "S3StorageDriver integrity check failed [bucket=#{bucket}, key=#{key}]: " \ "expected sha256:#{expected_hash}, got sha256:#{actual_hash}" end Api::Common::V1::Payload.decode(data) end end |
#store(context, payloads) ⇒ Array<StorageDriverClaim>
Store the given payloads.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb', line 71 def store(context, payloads) context_segments = context_key_segments(context.target, context.namespace) objects = payloads.map { |payload| stored_object(context, payload, context_segments) } uploads = objects.uniq { |object| [object.bucket, object.key] } run_concurrently(uploads, context.cancellation) do |object, cancellation| context.limiter.permit(object.payload) do cancellation.check! upload_if_absent(object) end end objects.map do |object| Converters::StorageDriverClaim.new( claim_data: { CLAIM_BUCKET => object.bucket, CLAIM_KEY => object.key, CLAIM_HASH_ALGORITHM => 'sha256', CLAIM_HASH_VALUE => object.hash_value } ) end end |
#type ⇒ String
Returns Always DRIVER_TYPE.
66 67 68 |
# File 'lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb', line 66 def type DRIVER_TYPE end |