Skip to content
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

Add new LambdaRuntime #353

Merged
merged 8 commits into from
Sep 5, 2024
Merged

Conversation

aryan-25
Copy link
Contributor

@aryan-25 aryan-25 commented Sep 4, 2024

Motivation:

As part of the implementation of the v2 API (#339), a new LambdaRuntimeClient was added (#348) and the Lambda.runLoop function added (#347).

This PR adds the LambdaRuntime which initializes a LambdaRuntimeClient and calls the Lambda.runLoop function with it.

Modifications:

  • Added a new LambdaRuntime.
  • Added the defaultEventLoop property to LambdaContext.
  • Added closure handler initializers to LambdaRuntime.

Result:

The runtime can now be used. A handler can be registered with LambdaRuntime and the runtime can be start listening for events through the run() function.

Comment on lines 48 to 54

/// The default EventLoop the Lambda is scheduled on.
package static var defaultEventLoop: any EventLoop {
get {
NIOSingletons.posixEventLoopGroup.next()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We must ensure that the eventLoop remains the same, in multiple invocations.

Suggested change
/// The default EventLoop the Lambda is scheduled on.
package static var defaultEventLoop: any EventLoop {
get {
NIOSingletons.posixEventLoopGroup.next()
}
}
/// The default EventLoop the Lambda is scheduled on.
package static let defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()

Add test:

    @Test
    func testDefaultEventLoopRemainsTheSame() {
        let eventLoop = Lambda.defaultEventLoop
        #expect(eventLoop === Lambda.defaultEventLoop)
    }


let ipAndPort = runtimeEndpoint.split(separator: ":", maxSplits: 1)
let ip = String(ipAndPort[0])
let port = Int(ipAndPort[1])!
Copy link
Member

Choose a reason for hiding this comment

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

we should throw an error here, if the second part is not an Int. .invalidPort.

let defaultHeaders: HTTPHeaders
/// These headers must be sent along an invocation or initialization error report
let errorHeaders: HTTPHeaders
/// These headers must be sent along an invocation or initialization error report
Copy link
Member

@fabianfett fabianfett Sep 5, 2024

Choose a reason for hiding this comment

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

code comment is not true.

Comment on lines 163 to 171
extension NewLambdaRuntime {
/// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
/// - Parameter body: The handler in the form of a closure.
package convenience init(
body: @Sendable @escaping (ByteBuffer, LambdaResponseStreamWriter, NewLambdaContext) async throws -> Void
) where Handler == StreamingClosureHandler {
self.init(handler: StreamingClosureHandler(body: body))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

this should be in the handler file I guess.

@fabianfett fabianfett marked this pull request as ready for review September 5, 2024 11:53
@fabianfett fabianfett merged commit 85b938e into swift-server:main Sep 5, 2024
9 of 13 checks passed
@fabianfett fabianfett added this to the 2.0 milestone Sep 5, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants