Skip to content

Commit bf1b08c

Browse files
fabianfetttomerd
authored andcommitted
Rename RequestWork to GetNextInvocation (#74)
1 parent b5f18da commit bf1b08c

9 files changed

+34
-34
lines changed

Sources/AWSLambdaRuntime/LambdaRunner.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ extension Lambda {
4545

4646
func run(logger: Logger, handler: Handler) -> EventLoopFuture<Void> {
4747
logger.debug("lambda invocation sequence starting")
48-
// 1. request work from lambda runtime engine
49-
return self.runtimeClient.requestWork(logger: logger).peekError { error in
50-
logger.error("could not fetch work from lambda runtime engine: \(error)")
48+
// 1. request invocation from lambda runtime engine
49+
return self.runtimeClient.getNextInvocation(logger: logger).peekError { error in
50+
logger.error("could not fetch invocation from lambda runtime engine: \(error)")
5151
}.flatMap { invocation, payload in
52-
// 2. send work to handler
52+
// 2. send invocation to handler
5353
let context = Context(logger: logger, eventLoop: self.eventLoop, invocation: invocation)
54-
logger.debug("sending work to lambda handler \(handler)")
54+
logger.debug("sending invocation to lambda handler \(handler)")
5555
return handler.handle(context: context, payload: payload)
5656
.mapResult { result in
5757
if case .failure(let error) = result {

Sources/AWSLambdaRuntime/LambdaRuntimeClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ extension Lambda {
3232
self.httpClient = HTTPClient(eventLoop: eventLoop, configuration: configuration)
3333
}
3434

35-
/// Requests work from the Runtime Engine.
36-
func requestWork(logger: Logger) -> EventLoopFuture<(Invocation, ByteBuffer)> {
37-
let url = Consts.invocationURLPrefix + Consts.requestWorkURLSuffix
35+
/// Requests invocation from the control plane.
36+
func getNextInvocation(logger: Logger) -> EventLoopFuture<(Invocation, ByteBuffer)> {
37+
let url = Consts.invocationURLPrefix + Consts.getNextInvocationURLSuffix
3838
logger.debug("requesting work from lambda runtime engine using \(url)")
3939
return self.httpClient.get(url: url).flatMapThrowing { response in
4040
guard response.status == .ok else {

Sources/AWSLambdaRuntime/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import NIO
1818
internal enum Consts {
1919
private static let apiPrefix = "/2018-06-01"
2020
static let invocationURLPrefix = "\(apiPrefix)/runtime/invocation"
21-
static let requestWorkURLSuffix = "/next"
21+
static let getNextInvocationURLSuffix = "/next"
2222
static let postResponseURLSuffix = "/response"
2323
static let postErrorURLSuffix = "/error"
2424
static let postInitErrorURL = "\(apiPrefix)/runtime/init/error"

Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private struct Behavior: LambdaServerBehavior {
211211
self.result = result
212212
}
213213

214-
func getWork() -> GetWorkResult {
214+
func getInvocation() -> GetInvocationResult {
215215
guard let payload = try? JSONEncoder().encode(Request(requestId: requestId)) else {
216216
XCTFail("encoding error")
217217
return .failure(.internalServerError)

Tests/AWSLambdaRuntimeTests/Lambda+StringTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private struct Behavior: LambdaServerBehavior {
210210
self.result = result
211211
}
212212

213-
func getWork() -> GetWorkResult {
213+
func getInvocation() -> GetInvocationResult {
214214
.success((requestId: self.requestId, payload: self.payload))
215215
}
216216

Tests/AWSLambdaRuntimeTests/LambdaRunnerTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LambdaRunnerTest: XCTestCase {
2020
struct Behavior: LambdaServerBehavior {
2121
let requestId = UUID().uuidString
2222
let payload = "hello"
23-
func getWork() -> GetWorkResult {
23+
func getInvocation() -> GetInvocationResult {
2424
.success((self.requestId, self.payload))
2525
}
2626

@@ -47,7 +47,7 @@ class LambdaRunnerTest: XCTestCase {
4747
struct Behavior: LambdaServerBehavior {
4848
static let error = "boom"
4949
let requestId = UUID().uuidString
50-
func getWork() -> GetWorkResult {
50+
func getInvocation() -> GetInvocationResult {
5151
.success((requestId: self.requestId, payload: "hello"))
5252
}
5353

Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTest.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class LambdaRuntimeClientTest: XCTestCase {
3636
XCTAssertEqual(behavior.state, 1)
3737
}
3838

39-
func testGetWorkServerInternalError() {
39+
func testGetInvocationServerInternalError() {
4040
struct Behavior: LambdaServerBehavior {
41-
func getWork() -> GetWorkResult {
41+
func getInvocation() -> GetInvocationResult {
4242
.failure(.internalServerError)
4343
}
4444

@@ -62,9 +62,9 @@ class LambdaRuntimeClientTest: XCTestCase {
6262
}
6363
}
6464

65-
func testGetWorkServerNoBodyError() {
65+
func testGetInvocationServerNoBodyError() {
6666
struct Behavior: LambdaServerBehavior {
67-
func getWork() -> GetWorkResult {
67+
func getInvocation() -> GetInvocationResult {
6868
.success(("1", ""))
6969
}
7070

@@ -88,9 +88,9 @@ class LambdaRuntimeClientTest: XCTestCase {
8888
}
8989
}
9090

91-
func testGetWorkServerMissingHeaderRequestIDError() {
91+
func testGetInvocationServerMissingHeaderRequestIDError() {
9292
struct Behavior: LambdaServerBehavior {
93-
func getWork() -> GetWorkResult {
93+
func getInvocation() -> GetInvocationResult {
9494
// no request id -> no context
9595
.success(("", "hello"))
9696
}
@@ -117,7 +117,7 @@ class LambdaRuntimeClientTest: XCTestCase {
117117

118118
func testProcessResponseInternalServerError() {
119119
struct Behavior: LambdaServerBehavior {
120-
func getWork() -> GetWorkResult {
120+
func getInvocation() -> GetInvocationResult {
121121
.success((requestId: "1", payload: "payload"))
122122
}
123123

@@ -142,7 +142,7 @@ class LambdaRuntimeClientTest: XCTestCase {
142142

143143
func testProcessErrorInternalServerError() {
144144
struct Behavior: LambdaServerBehavior {
145-
func getWork() -> GetWorkResult {
145+
func getInvocation() -> GetInvocationResult {
146146
.success((requestId: "1", payload: "payload"))
147147
}
148148

@@ -167,8 +167,8 @@ class LambdaRuntimeClientTest: XCTestCase {
167167

168168
func testProcessInitErrorOnBootstrapFailure() {
169169
struct Behavior: LambdaServerBehavior {
170-
func getWork() -> GetWorkResult {
171-
XCTFail("should not get work")
170+
func getInvocation() -> GetInvocationResult {
171+
XCTFail("should not get invocation")
172172
return .failure(.internalServerError)
173173
}
174174

@@ -217,7 +217,7 @@ class LambdaRuntimeClientTest: XCTestCase {
217217
return .success(())
218218
}
219219

220-
func getWork() -> GetWorkResult {
220+
func getInvocation() -> GetInvocationResult {
221221
self.state += 2
222222
return .success(("1", "hello"))
223223
}

Tests/AWSLambdaRuntimeTests/LambdaTest.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class LambdaTest: XCTestCase {
100100

101101
func testBootstrapFailureAndReportErrorFailure() {
102102
struct Behavior: LambdaServerBehavior {
103-
func getWork() -> GetWorkResult {
104-
XCTFail("should not get work")
103+
func getInvocation() -> GetInvocationResult {
104+
XCTFail("should not get invocation")
105105
return .failure(.internalServerError)
106106
}
107107

@@ -212,7 +212,7 @@ class LambdaTest: XCTestCase {
212212
defer { XCTAssertNoThrow(try server.stop().wait()) }
213213

214214
struct Behavior: LambdaServerBehavior {
215-
func getWork() -> GetWorkResult {
215+
func getInvocation() -> GetInvocationResult {
216216
.failure(.internalServerError)
217217
}
218218

@@ -299,7 +299,7 @@ private struct Behavior: LambdaServerBehavior {
299299
self.result = result
300300
}
301301

302-
func getWork() -> GetWorkResult {
302+
func getInvocation() -> GetInvocationResult {
303303
.success((requestId: self.requestId, payload: self.payload))
304304
}
305305

@@ -334,8 +334,8 @@ private struct Behavior: LambdaServerBehavior {
334334
}
335335

336336
struct FailedBootstrapBehavior: LambdaServerBehavior {
337-
func getWork() -> GetWorkResult {
338-
XCTFail("should not get work")
337+
func getInvocation() -> GetInvocationResult {
338+
XCTFail("should not get invocation")
339339
return .failure(.internalServerError)
340340
}
341341

Tests/AWSLambdaRuntimeTests/MockLambdaServer.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ internal final class HTTPHandler: ChannelInboundHandler {
130130
case .failure(let error):
131131
responseStatus = .init(statusCode: error.rawValue)
132132
}
133-
} else if request.head.uri.hasSuffix(Consts.requestWorkURLSuffix) {
134-
switch self.behavior.getWork() {
133+
} else if request.head.uri.hasSuffix(Consts.getNextInvocationURLSuffix) {
134+
switch self.behavior.getInvocation() {
135135
case .success(let (requestId, result)):
136136
if requestId == "timeout" {
137137
usleep((UInt32(result) ?? 0) * 1000)
@@ -213,13 +213,13 @@ internal final class HTTPHandler: ChannelInboundHandler {
213213
}
214214

215215
internal protocol LambdaServerBehavior {
216-
func getWork() -> GetWorkResult
216+
func getInvocation() -> GetInvocationResult
217217
func processResponse(requestId: String, response: String?) -> Result<Void, ProcessResponseError>
218218
func processError(requestId: String, error: ErrorResponse) -> Result<Void, ProcessErrorError>
219219
func processInitError(error: ErrorResponse) -> Result<Void, ProcessErrorError>
220220
}
221221

222-
internal typealias GetWorkResult = Result<(String, String), GetWorkError>
222+
internal typealias GetInvocationResult = Result<(String, String), GetWorkError>
223223

224224
internal enum GetWorkError: Int, Error {
225225
case badRequest = 400

0 commit comments

Comments
 (0)