Skip to content

Bump soto-s3-file-transfer to 2.x #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ DerivedData/
.netrc
/.lambda/
/.vscode/
.swiftpm/
46 changes: 32 additions & 14 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "291438696abdd48d2a83b52465c176efbd94512b",
"version" : "1.20.1"
"revision" : "333f51104b75d1a5b94cb3b99e4c58a3b442c9f7",
"version" : "1.25.2"
}
},
{
Expand All @@ -32,26 +32,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/soto-project/soto.git",
"state" : {
"revision" : "c28c3efa72e6beceae6f38f8c8fe18e7c57e3418",
"version" : "6.8.0"
"revision" : "141b3c944f3f4a9ad428280e8ad94f6f437e0f00",
"version" : "7.5.0"
}
},
{
"identity" : "soto-core",
"kind" : "remoteSourceControl",
"location" : "https://github.com/soto-project/soto-core.git",
"state" : {
"revision" : "3ed66ec536bc372360d7e3ec39a5e8b1870747ea",
"version" : "6.5.2"
"revision" : "a61299aa18626e462312984765d34146286b29d3",
"version" : "7.4.0"
}
},
{
"identity" : "soto-s3-file-transfer",
"kind" : "remoteSourceControl",
"location" : "https://github.com/soto-project/soto-s3-file-transfer.git",
"state" : {
"revision" : "da375d7544080e8f00dba3bb573d7a412f3c4b41",
"version" : "1.3.0"
"revision" : "5104491d1a8f76a2839e4476e9644b3885ba758c",
"version" : "2.1.0"
}
},
{
Expand Down Expand Up @@ -135,6 +135,15 @@
"version" : "1.2.2"
}
},
{
"identity" : "swift-distributed-tracing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-distributed-tracing.git",
"state" : {
"revision" : "a64a0abc2530f767af15dd88dda7f64d5f1ff9de",
"version" : "1.2.0"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -167,8 +176,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version" : "2.64.0"
"revision" : "c51907a839e63ebf0ba2076bba73dd96436bd1b9",
"version" : "2.81.0"
}
},
{
Expand All @@ -194,8 +203,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5",
"version" : "2.26.0"
"revision" : "0cc3528ff48129d64ab9cab0b1cd621634edfc6b",
"version" : "2.29.3"
}
},
{
Expand All @@ -216,6 +225,15 @@
"version" : "1.0.2"
}
},
{
"identity" : "swift-service-context",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-service-context.git",
"state" : {
"revision" : "8946c930cae601452149e45d31d8ddfac973c3c7",
"version" : "1.2.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand All @@ -230,8 +248,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
"revision" : "a34201439c74b53f0fd71ef11741af7e7caf01e1",
"version" : "1.4.2"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "0.1.0"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha.1"),
.package(url: "https://github.com/soto-project/soto-s3-file-transfer.git", from: "1.2.0"),
.package(url: "https://github.com/soto-project/soto-s3-file-transfer.git", from: "2.0.0"),
.package(url: "https://github.com/vapor-community/Zip.git", from: "2.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies.git", from: "1.0.0")
],
Expand Down
11 changes: 3 additions & 8 deletions Sources/DocUploader/DocUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ public struct DocUploader: LambdaHandler {
}
self.httpClient = httpClient

let awsClient = AWSClient(httpClientProvider: .shared(httpClient))
let awsClient = AWSClient(httpClient: httpClient)
context.terminator.register(name: "awsclient") { eventLoop in
let promise = eventLoop.makePromise(of: Void.self)
awsClient.shutdown() { error in
switch error {
case .none:
promise.succeed(())
case .some(let error):
promise.fail(error)
}
promise.completeWithTask {
try await awsClient.shutdown()
}
return promise.futureResult
}
Expand Down
21 changes: 6 additions & 15 deletions Sources/DocUploader/LiveS3Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SotoS3FileTransfer
struct LiveS3Client: S3Client {
func deleteFile(client: AWSClient, logger: Logger, key: S3StoreKey) async throws {
let s3 = S3(client: client, region: .useast2)
let s3FileTransfer = S3FileTransferManager(s3: s3, threadPoolProvider: .singleton)
let s3FileTransfer = S3FileTransferManager(s3: s3)

guard let file = S3File(key: key) else {
throw Error(message: "Invalid key: \(key)")
Expand All @@ -30,7 +30,7 @@ struct LiveS3Client: S3Client {

func loadFile(client: AWSClient, logger: Logger, from key: S3StoreKey, to path: String) async throws {
let s3 = S3(client: client, region: .useast2)
let s3FileTransfer = S3FileTransferManager(s3: s3, threadPoolProvider: .singleton)
let s3FileTransfer = S3FileTransferManager(s3: s3)

guard let file = S3File(key: key) else {
throw Error(message: "Invalid key: \(key)")
Expand All @@ -44,26 +44,17 @@ struct LiveS3Client: S3Client {
timeout: .seconds(60),
options: .s3DisableChunkedUploads)

let threadPool = NIOThreadPool(numberOfThreads: 8)
defer { threadPool.shutdownGracefully { _ in } }
threadPool.start()

let s3FileTransfer = S3FileTransferManager(s3: s3,
threadPoolProvider: .shared(threadPool),
configuration: .init(maxConcurrentTasks: 60))
defer {
try? s3FileTransfer.syncShutdown()
}
let s3FileTransfer = S3FileTransferManager(s3: s3, configuration: .init(maxConcurrentTasks: 60))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-fowler it looks like there were some API changes around thread provider and shutdown - do these changes make sense to you? I'm guessing the S3FileTransferManager taps into the underlying S3 client now?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good as far as I can tell


guard let s3Folder = S3Folder(url: key.url) else {
throw Error(message: "Invalid key: \(key)")
}

var nextProgressTick = 0.1
let nextProgressTick = QueueIsolated(0.1)
try await s3FileTransfer.sync(from: folder, to: s3Folder, delete: true) { progress in
if progress >= nextProgressTick {
if progress >= nextProgressTick.value {
logger.info("Syncing... [\(percent: progress)]")
nextProgressTick += 0.1
nextProgressTick.withValue { $0 += 0.1 }
}
}
}
Expand Down
69 changes: 69 additions & 0 deletions Sources/DocUploader/QueueIsolated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation


// Modeled after ActorIsolated with synchronisation via a queue instead of an actor, allowing
// sync access where async isn't possible.

@dynamicMemberLookup
public final class QueueIsolated<Value: Sendable>: @unchecked Sendable {
private let _queue = DispatchQueue(label: "queue-isolated")

private var _value: Value

public init(_ value: Value) {
self._value = value
}

public var value: Value {
get {
_queue.sync { self._value }
}
}

public subscript<Subject>(dynamicMember keyPath: KeyPath<Value, Subject>) -> Subject {
_queue.sync {
self._value[keyPath: keyPath]
}
}

public func withValue<T>(
_ operation: (inout Value) throws -> T
) rethrows -> T {
try _queue.sync {
var value = self._value
defer { self._value = value }
return try operation(&value)
}
}

public func setValue(_ newValue: Value) {
_queue.async {
self._value = newValue
}
}
}


extension QueueIsolated where Value == Int {
public func increment(by delta: Int = 1) {
withValue { $0 += delta }
}

public func decrement(by delta: Int = 1) {
withValue { $0 -= delta }
}
}