Skip to content

Commit

Permalink
Merge pull request #44 from oheyadam/better-offline-support
Browse files Browse the repository at this point in the history
Better offline support in AWS implementation
  • Loading branch information
liutikas committed Feb 9, 2024
2 parents 84256cb + 739fb18 commit ff6ef9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class S3BuildCacheService(
}

override fun store(key: BuildCacheKey, writer: BuildCacheEntryWriter) {
if (writer.size == 0L) return // do not store empty entries into the cache
logger.info("Storing ${key.blobKey()}")
val cacheKey = key.blobKey()
val output = ByteArrayOutputStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ class S3StorageService(
}

override fun validateConfiguration() {
val buckets = client.listBuckets().buckets()
if (buckets.none { bucket -> bucket.name() == bucketName }) {
throw Exception("Bucket $bucketName under project $region cannot be found or it is not accessible using the provided credentials")
try {
val buckets = client.listBuckets().buckets()
if (buckets.none { bucket -> bucket.name() == bucketName }) {
throw Exception("Bucket $bucketName under project $region cannot be found or is not accessible using the provided credentials")
}
} catch (e: Exception) {
logger.warn("Couldn't validate S3 client config: ${e.message}")
}
}

Expand All @@ -127,6 +131,7 @@ class S3StorageService(
return try {
val inputStream = client.getObject(request)
val blob = inputStream.response() ?: return null
if (blob.contentLength() == 0L) return null // return empty entries as a cache miss
if (blob.contentLength() > sizeThreshold) {
val path = FileHandleInputStream.create()
val outputStream = path.outputStream()
Expand Down Expand Up @@ -162,7 +167,12 @@ class S3StorageService(
}

private fun delete(client: S3Client, request: DeleteObjectRequest): Boolean {
return client.deleteObject(request).deleteMarker()
return try {
client.deleteObject(request).deleteMarker()
} catch (e: Exception) {
logger.debug("Unable to delete $request", e)
false
}
}
}
}

0 comments on commit ff6ef9c

Please sign in to comment.