Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

Commit

Permalink
Renamed LambdaRuntime to Runtime (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfett authored Jan 16, 2020
1 parent 65345c0 commit 5b9b72b
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 37 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ let package = Package(
"LambdaEvents",
"LambdaRuntime",
"LambdaRuntimeTestUtils",
"NIO",
"NIOTestUtils",
"Logging",
])
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let handler = APIGateway.handler() { (request, ctx) in
}
}

let runtime = try LambdaRuntime.createRuntime(eventLoopGroup: group, handler: handler)
let runtime = try Runtime.createRuntime(eventLoopGroup: group, handler: handler)
defer { try! runtime.syncShutdown() }
try runtime.start().wait()
```
Expand Down Expand Up @@ -130,9 +130,9 @@ let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer { try! group.syncShutdownGracefully() }

do {
let runtime = try LambdaRuntime.createRuntime(
let runtime = try Runtime.createRuntime(
eventLoopGroup: group,
handler: LambdaRuntime.codable(squareNumber))
handler: Runtime.codable(squareNumber))

defer { try! runtime.syncShutdown() }

Expand Down
2 changes: 1 addition & 1 deletion Sources/LambdaRuntime/Runtime+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import NIO
import NIOFoundationCompat

extension LambdaRuntime {
extension Runtime {

/// wrapper to use for the register function that wraps the encoding and decoding
public static func codable<Event: Decodable, Result: Encodable>(
Expand Down
6 changes: 3 additions & 3 deletions Sources/LambdaRuntime/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct InvocationError: Codable {
let errorMessage: String
}

final public class LambdaRuntime {
final public class Runtime {

public typealias Handler = (NIO.ByteBuffer, Context) -> EventLoopFuture<NIO.ByteBuffer?>

Expand All @@ -29,14 +29,14 @@ final public class LambdaRuntime {

/// the runtime shall be initialised with an EventLoopGroup, that is used throughout the lambda
public static func createRuntime(eventLoopGroup: EventLoopGroup, environment: Environment? = nil, handler: @escaping Handler)
throws -> LambdaRuntime
throws -> Runtime
{
let env = try environment ?? Environment()

let client = RuntimeAPIClient(
eventLoopGroup: eventLoopGroup,
lambdaRuntimeAPI: env.lambdaRuntimeAPI)
let runtime = LambdaRuntime(
let runtime = Runtime(
eventLoopGroup: eventLoopGroup,
client: client,
environment: env,
Expand Down
10 changes: 5 additions & 5 deletions Tests/LambdaRuntimeTests/Runtime+CodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RuntimeCodableTests: XCTestCase {
defer {
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
}
let handler = LambdaRuntime.codable { (req: TestRequest, ctx) -> EventLoopFuture<TestResponse> in
let handler = Runtime.codable { (req: TestRequest, ctx) -> EventLoopFuture<TestResponse> in
return ctx.eventLoop.makeSucceededFuture(TestResponse(greeting: "Hello \(req.name)!"))
}

Expand All @@ -52,7 +52,7 @@ class RuntimeCodableTests: XCTestCase {
defer {
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
}
let handler = LambdaRuntime.codable { (req: TestRequest, ctx) -> EventLoopFuture<TestResponse> in
let handler = Runtime.codable { (req: TestRequest, ctx) -> EventLoopFuture<TestResponse> in
return ctx.eventLoop.makeSucceededFuture(TestResponse(greeting: "Hello \(req.name)!"))
}

Expand Down Expand Up @@ -81,7 +81,7 @@ class RuntimeCodableTests: XCTestCase {
defer {
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
}
let handler = LambdaRuntime.codable { (req: TestRequest, ctx) -> EventLoopFuture<Void> in
let handler = Runtime.codable { (req: TestRequest, ctx) -> EventLoopFuture<Void> in
return ctx.eventLoop.makeSucceededFuture(Void())
}

Expand All @@ -101,7 +101,7 @@ class RuntimeCodableTests: XCTestCase {
defer {
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
}
let handler = LambdaRuntime.codable { (req: TestRequest, ctx) -> EventLoopFuture<Void> in
let handler = Runtime.codable { (req: TestRequest, ctx) -> EventLoopFuture<Void> in
return ctx.eventLoop.makeSucceededFuture(Void())
}

Expand All @@ -127,7 +127,7 @@ class RuntimeCodableTests: XCTestCase {
defer {
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
}
let handler = LambdaRuntime.codable { (req: TestRequest, ctx) -> EventLoopFuture<Void> in
let handler = Runtime.codable { (req: TestRequest, ctx) -> EventLoopFuture<Void> in
return ctx.eventLoop.makeFailedFuture(RuntimeError.unknown)
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/LambdaRuntimeTests/RuntimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RuntimeTests: XCTestCase {
defer { XCTAssertNoThrow(try group.syncShutdownGracefully()) }

do {
let runtime = try LambdaRuntime.createRuntime(eventLoopGroup: group) { (_, ctx) in
let runtime = try Runtime.createRuntime(eventLoopGroup: group) { (_, ctx) in
return ctx.eventLoop.makeSucceededFuture(nil)
}
defer { XCTAssertNoThrow(try runtime.syncShutdown()) }
Expand All @@ -34,7 +34,7 @@ class RuntimeTests: XCTestCase {
defer { XCTAssertNoThrow(try group.syncShutdownGracefully()) }

do {
let runtime = try LambdaRuntime.createRuntime(eventLoopGroup: group) { (_, ctx) in
let runtime = try Runtime.createRuntime(eventLoopGroup: group) { (_, ctx) in
return ctx.eventLoop.makeSucceededFuture(nil)
}
defer { XCTAssertNoThrow(try runtime.syncShutdown()) }
Expand Down
14 changes: 7 additions & 7 deletions examples/EventSources/Sources/EventSources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,28 @@ func printOriginalPayload(_ handler: @escaping (NIO.ByteBuffer, Context) -> Even
do {
logger.info("start runtime")
let environment = try Environment()
let handler: LambdaRuntime.Handler
let handler: Runtime.Handler

switch environment.handlerName {
case "sns":
handler = printOriginalPayload(LambdaRuntime.codable(handleSNS))
handler = printOriginalPayload(Runtime.codable(handleSNS))
case "sqs":
handler = printOriginalPayload(LambdaRuntime.codable(handleSQS))
handler = printOriginalPayload(Runtime.codable(handleSQS))
case "dynamo":
handler = printOriginalPayload(LambdaRuntime.codable(handleDynamoStream))
handler = printOriginalPayload(Runtime.codable(handleDynamoStream))
case "schedule":
handler = printOriginalPayload(LambdaRuntime.codable(handleCloudwatchSchedule))
handler = printOriginalPayload(Runtime.codable(handleCloudwatchSchedule))
case "api":
handler = printOriginalPayload(APIGateway.handler(handleAPIRequest))
case "s3":
handler = printOriginalPayload(LambdaRuntime.codable(handleS3))
handler = printOriginalPayload(Runtime.codable(handleS3))
case "loadbalancer":
handler = printOriginalPayload(ALB.handler(multiValueHeadersEnabled: true, handleLoadBalancerRequest))
default:
handler = printPayload
}

let runtime = try LambdaRuntime.createRuntime(eventLoopGroup: group, handler: handler)
let runtime = try Runtime.createRuntime(eventLoopGroup: group, handler: handler)
defer { try! runtime.syncShutdown() }
logger.info("starting runloop")

Expand Down
8 changes: 4 additions & 4 deletions examples/SquareNumber/Sources/SquareNumber/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ defer {

do {

let handler: LambdaRuntime.Handler
let handler: Runtime.Handler
switch ProcessInfo.processInfo.environment["_HANDLER"] {
case "printNumber":
handler = LambdaRuntime.codable(printNumber)
handler = Runtime.codable(printNumber)
default:
handler = LambdaRuntime.codable(squareNumber)
handler = Runtime.codable(squareNumber)
}

let runtime = try LambdaRuntime.createRuntime(eventLoopGroup: group, handler: handler)
let runtime = try Runtime.createRuntime(eventLoopGroup: group, handler: handler)
defer { try! runtime.syncShutdown() }

try runtime.start().wait()
Expand Down
9 changes: 0 additions & 9 deletions examples/TodoAPIGateway/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@
"version": "2.5.0"
}
},
{
"package": "swift-nio-ssl-support",
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
"state": {
"branch": null,
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
"version": "1.0.0"
}
},
{
"package": "swift-nio-transport-services",
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
Expand Down
4 changes: 2 additions & 2 deletions examples/TodoAPIGateway/Sources/TodoAPIGateway/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ do {

logger.info("register function")

let handler: LambdaRuntime.Handler
let handler: Runtime.Handler
switch env.handlerName {
case "list":
handler = APIGateway.handler(controller.listTodos)
Expand All @@ -47,7 +47,7 @@ do {

logger.info("starting runloop")

let runtime = try LambdaRuntime.createRuntime(eventLoopGroup: group, environment: env, handler: handler)
let runtime = try Runtime.createRuntime(eventLoopGroup: group, environment: env, handler: handler)
defer { try! runtime.syncShutdown() }
try runtime.start().wait()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer { try! group.syncShutdownGracefully() }

do {
let runtime = try LambdaRuntime.createRuntime(eventLoopGroup: group, handler: echoCall)
let runtime = try Runtime.createRuntime(eventLoopGroup: group, handler: echoCall)
defer { try! runtime.syncShutdown() }

try runtime.start().wait()
Expand Down

0 comments on commit 5b9b72b

Please sign in to comment.