Skip to content

Commit ce95e74

Browse files
Merge pull request #35 from SwiftPackageIndex/update-soto-s3-file-transfer
Bump soto-s3-file-transfer to 2.x
2 parents 8886eba + e79d038 commit ce95e74

File tree

8 files changed

+114
-40
lines changed

8 files changed

+114
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ DerivedData/
99
.netrc
1010
/.lambda/
1111
/.vscode/
12+
.swiftpm/

Package.resolved

Lines changed: 32 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let package = Package(
3939
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
4040
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "0.1.0"),
4141
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha.1"),
42-
.package(url: "https://github.com/soto-project/soto-s3-file-transfer.git", from: "1.2.0"),
42+
.package(url: "https://github.com/soto-project/soto-s3-file-transfer.git", from: "2.0.0"),
4343
.package(url: "https://github.com/vapor-community/Zip.git", from: "2.0.0"),
4444
.package(url: "https://github.com/pointfreeco/swift-dependencies.git", from: "1.0.0")
4545
],

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Instead, use the `dev` environment to validate a new release as follows:
4444
- Run the tests
4545

4646
```
47-
docker run --rm -v "$PWD":/host -w /host swift:5.10.0-amazonlinux2 swift test
47+
docker run --rm -v "$PWD":/host -w /host swift:6.0.3-amazonlinux2 swift test
4848
```
4949
5050
- Deploy the new version to the "test" lambda

Sources/DocUploader/DocUploader.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,11 @@ public struct DocUploader: LambdaHandler {
4848
}
4949
self.httpClient = httpClient
5050

51-
let awsClient = AWSClient(httpClientProvider: .shared(httpClient))
51+
let awsClient = AWSClient(httpClient: httpClient)
5252
context.terminator.register(name: "awsclient") { eventLoop in
5353
let promise = eventLoop.makePromise(of: Void.self)
54-
awsClient.shutdown() { error in
55-
switch error {
56-
case .none:
57-
promise.succeed(())
58-
case .some(let error):
59-
promise.fail(error)
60-
}
54+
promise.completeWithTask {
55+
try await awsClient.shutdown()
6156
}
6257
return promise.futureResult
6358
}

Sources/DocUploader/LiveS3Client.swift

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SotoS3FileTransfer
2020
struct LiveS3Client: S3Client {
2121
func deleteFile(client: AWSClient, logger: Logger, key: S3StoreKey) async throws {
2222
let s3 = S3(client: client, region: .useast2)
23-
let s3FileTransfer = S3FileTransferManager(s3: s3, threadPoolProvider: .singleton)
23+
let s3FileTransfer = S3FileTransferManager(s3: s3)
2424

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

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

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

47-
let threadPool = NIOThreadPool(numberOfThreads: 8)
48-
defer { threadPool.shutdownGracefully { _ in } }
49-
threadPool.start()
50-
51-
let s3FileTransfer = S3FileTransferManager(s3: s3,
52-
threadPoolProvider: .shared(threadPool),
53-
configuration: .init(maxConcurrentTasks: 60))
54-
defer {
55-
try? s3FileTransfer.syncShutdown()
56-
}
47+
let s3FileTransfer = S3FileTransferManager(s3: s3, configuration: .init(maxConcurrentTasks: 60))
5748

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

62-
var nextProgressTick = 0.1
53+
let nextProgressTick = QueueIsolated(0.1)
6354
try await s3FileTransfer.sync(from: folder, to: s3Folder, delete: true) { progress in
64-
if progress >= nextProgressTick {
55+
if progress >= nextProgressTick.value {
6556
logger.info("Syncing... [\(percent: progress)]")
66-
nextProgressTick += 0.1
57+
nextProgressTick.withValue { $0 += 0.1 }
6758
}
6859
}
6960
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
18+
// Modeled after ActorIsolated with synchronisation via a queue instead of an actor, allowing
19+
// sync access where async isn't possible.
20+
21+
@dynamicMemberLookup
22+
public final class QueueIsolated<Value: Sendable>: @unchecked Sendable {
23+
private let _queue = DispatchQueue(label: "queue-isolated")
24+
25+
private var _value: Value
26+
27+
public init(_ value: Value) {
28+
self._value = value
29+
}
30+
31+
public var value: Value {
32+
get {
33+
_queue.sync { self._value }
34+
}
35+
}
36+
37+
public subscript<Subject>(dynamicMember keyPath: KeyPath<Value, Subject>) -> Subject {
38+
_queue.sync {
39+
self._value[keyPath: keyPath]
40+
}
41+
}
42+
43+
public func withValue<T>(
44+
_ operation: (inout Value) throws -> T
45+
) rethrows -> T {
46+
try _queue.sync {
47+
var value = self._value
48+
defer { self._value = value }
49+
return try operation(&value)
50+
}
51+
}
52+
53+
public func setValue(_ newValue: Value) {
54+
_queue.async {
55+
self._value = newValue
56+
}
57+
}
58+
}
59+
60+
61+
extension QueueIsolated where Value == Int {
62+
public func increment(by delta: Int = 1) {
63+
withValue { $0 += delta }
64+
}
65+
66+
public func decrement(by delta: Int = 1) {
67+
withValue { $0 -= delta }
68+
}
69+
}

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ docker run \
2222
--rm \
2323
--volume "$(pwd):/src" \
2424
--workdir "/src" \
25-
swift:5.10.0-amazonlinux2 \
25+
swift:6.0.3-amazonlinux2 \
2626
swift build --disable-automatic-resolution --product "$executable" -c release --static-swift-stdlib #-Xswiftc -cross-module-optimization

0 commit comments

Comments
 (0)