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

8 files changed

+114
-40
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ DerivedData/
99
.netrc
1010
/.lambda/
1111
/.vscode/
12+
.swiftpm/

Package.resolved

+32-14
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"kind" : "remoteSourceControl",
66
"location" : "https://github.com/swift-server/async-http-client.git",
77
"state" : {
8-
"revision" : "291438696abdd48d2a83b52465c176efbd94512b",
9-
"version" : "1.20.1"
8+
"revision" : "333f51104b75d1a5b94cb3b99e4c58a3b442c9f7",
9+
"version" : "1.25.2"
1010
}
1111
},
1212
{
@@ -32,26 +32,26 @@
3232
"kind" : "remoteSourceControl",
3333
"location" : "https://github.com/soto-project/soto.git",
3434
"state" : {
35-
"revision" : "c28c3efa72e6beceae6f38f8c8fe18e7c57e3418",
36-
"version" : "6.8.0"
35+
"revision" : "141b3c944f3f4a9ad428280e8ad94f6f437e0f00",
36+
"version" : "7.5.0"
3737
}
3838
},
3939
{
4040
"identity" : "soto-core",
4141
"kind" : "remoteSourceControl",
4242
"location" : "https://github.com/soto-project/soto-core.git",
4343
"state" : {
44-
"revision" : "3ed66ec536bc372360d7e3ec39a5e8b1870747ea",
45-
"version" : "6.5.2"
44+
"revision" : "a61299aa18626e462312984765d34146286b29d3",
45+
"version" : "7.4.0"
4646
}
4747
},
4848
{
4949
"identity" : "soto-s3-file-transfer",
5050
"kind" : "remoteSourceControl",
5151
"location" : "https://github.com/soto-project/soto-s3-file-transfer.git",
5252
"state" : {
53-
"revision" : "da375d7544080e8f00dba3bb573d7a412f3c4b41",
54-
"version" : "1.3.0"
53+
"revision" : "5104491d1a8f76a2839e4476e9644b3885ba758c",
54+
"version" : "2.1.0"
5555
}
5656
},
5757
{
@@ -135,6 +135,15 @@
135135
"version" : "1.2.2"
136136
}
137137
},
138+
{
139+
"identity" : "swift-distributed-tracing",
140+
"kind" : "remoteSourceControl",
141+
"location" : "https://github.com/apple/swift-distributed-tracing.git",
142+
"state" : {
143+
"revision" : "a64a0abc2530f767af15dd88dda7f64d5f1ff9de",
144+
"version" : "1.2.0"
145+
}
146+
},
138147
{
139148
"identity" : "swift-http-types",
140149
"kind" : "remoteSourceControl",
@@ -167,8 +176,8 @@
167176
"kind" : "remoteSourceControl",
168177
"location" : "https://github.com/apple/swift-nio.git",
169178
"state" : {
170-
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
171-
"version" : "2.64.0"
179+
"revision" : "c51907a839e63ebf0ba2076bba73dd96436bd1b9",
180+
"version" : "2.81.0"
172181
}
173182
},
174183
{
@@ -194,8 +203,8 @@
194203
"kind" : "remoteSourceControl",
195204
"location" : "https://github.com/apple/swift-nio-ssl.git",
196205
"state" : {
197-
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5",
198-
"version" : "2.26.0"
206+
"revision" : "0cc3528ff48129d64ab9cab0b1cd621634edfc6b",
207+
"version" : "2.29.3"
199208
}
200209
},
201210
{
@@ -216,6 +225,15 @@
216225
"version" : "1.0.2"
217226
}
218227
},
228+
{
229+
"identity" : "swift-service-context",
230+
"kind" : "remoteSourceControl",
231+
"location" : "https://github.com/apple/swift-service-context.git",
232+
"state" : {
233+
"revision" : "8946c930cae601452149e45d31d8ddfac973c3c7",
234+
"version" : "1.2.0"
235+
}
236+
},
219237
{
220238
"identity" : "swift-syntax",
221239
"kind" : "remoteSourceControl",
@@ -230,8 +248,8 @@
230248
"kind" : "remoteSourceControl",
231249
"location" : "https://github.com/apple/swift-system.git",
232250
"state" : {
233-
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
234-
"version" : "1.2.1"
251+
"revision" : "a34201439c74b53f0fd71ef11741af7e7caf01e1",
252+
"version" : "1.4.2"
235253
}
236254
},
237255
{

Package.swift

+1-1
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

+1-1
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

+3-8
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

+6-15
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
}
+69
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

+1-1
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)