Skip to content

Commit 0b733f4

Browse files
committed
add comments and sample code for usage with ServiceLifecycle
1 parent fc2e6d5 commit 0b733f4

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Examples/quoteapi/Sources/QuoteAPI/QuoteService.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import Foundation
1717
import OpenAPIRuntime
1818
import OpenAPILambda
19+
// import ServiceLifecycle
1920

2021
@main
2122
struct QuoteServiceImpl: APIProtocol, OpenAPILambdaHttpApi {
@@ -25,8 +26,28 @@ struct QuoteServiceImpl: APIProtocol, OpenAPILambdaHttpApi {
2526
}
2627

2728
static func main() async throws {
28-
let lambdaRuntime = try LambdaRuntime(body: Self.handler())
29-
try await lambdaRuntime.run()
29+
// when you just need to run the Lambda function, call run()
30+
try await Self.run()
31+
32+
// when you need to have access to the runtime for advanced usage (dependency injection, Service LifeCycle, etc)
33+
// create the LambdaRuntime and run it
34+
35+
// here is an example with Service Lifecycle
36+
// Add the follwing in Package.swift
37+
// .package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.0"),
38+
// and
39+
// .product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
40+
// Add `import ServiceLifecycle` at the top of this file`
41+
42+
// let lambdaRuntime = try LambdaRuntime(body: Self.handler())
43+
// try await lambdaRuntime.run()
44+
// let serviceGroup = ServiceGroup(
45+
// services: [lambdaRuntime],
46+
// gracefulShutdownSignals: [.sigterm],
47+
// cancellationSignals: [.sigint],
48+
// logger: Logger(label: "ServiceGroup")
49+
// )
50+
// try await serviceGroup.run()
3051
}
3152

3253
func getQuote(_ input: Operations.getQuote.Input) async throws -> Operations.getQuote.Output {

0 commit comments

Comments
 (0)