-
Notifications
You must be signed in to change notification settings - Fork 0
Remove BreezeLambdaService #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
96f7097
45957ef
8034431
e2bb315
279f068
5a8807a
671ad87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| FROM swift:6.2.0 | ||
|
|
||
| RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
| && apt-get -y install --no-install-recommends make git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
| // README at: https://github.com/devcontainers/templates/tree/main/src/docker-outside-of-docker-compose | ||
| { | ||
| "name": "Docker from Docker Compose", | ||
| "dockerComposeFile": "docker-compose.yml", | ||
| "service": "app", | ||
| "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
|
|
||
| // Use this environment variable if you need to bind mount your local source code into a new container. | ||
| "remoteEnv": { | ||
| "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" | ||
| }, | ||
|
|
||
| "features": { | ||
| "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { | ||
| "version": "latest", | ||
| "enableNonRootDocker": "true", | ||
| "moby": "true" | ||
| }, | ||
| "ghcr.io/devcontainers/features/aws-cli:1": {} | ||
| }, | ||
| // Configure tool-specific properties. | ||
| "customizations": { | ||
| // Configure properties specific to VS Code. | ||
| "vscode": { | ||
| // Set *default* container specific settings.json values on container create. | ||
| "settings": { | ||
| "lldb.library": "/usr/lib/liblldb.so" | ||
| }, | ||
| // Add the IDs of extensions you want installed when the container is created. | ||
| "extensions": [ | ||
| "swiftlang.swift-vscode" | ||
| ] | ||
| } | ||
| }, | ||
| // Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
| // "forwardPorts": [], | ||
|
|
||
| // Use 'postCreateCommand' to run commands after the container is created. | ||
| // "postCreateCommand": "docker --version", | ||
|
|
||
| // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
| // "remoteUser": "vscode" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| version: '3' | ||
|
|
||
| services: | ||
| app: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
|
|
||
| volumes: | ||
| # Forwards the local Docker socket to the container. | ||
| - /var/run/docker.sock:/var/run/docker-host.sock | ||
| # Update this to wherever you want VS Code to mount the folder of your project | ||
| - ../..:/workspaces:cached | ||
|
|
||
| # Overrides default command so things don't shut down after the process ends. | ||
| entrypoint: /usr/local/share/docker-init.sh | ||
| depends_on: | ||
| - localstack | ||
| environment: | ||
| - LOCALSTACK_ENDPOINT=http://localstack:4566 | ||
| - AWS_ACCESS_KEY_ID=test | ||
| - AWS_SECRET_ACCESS_KEY=test | ||
| - AWS_REGION=us-east-1 | ||
| command: sleep infinity | ||
|
|
||
| # Uncomment the next four lines if you will use a ptrace-based debuggers like C++, Go, and Rust. | ||
| cap_add: | ||
| - SYS_PTRACE | ||
| security_opt: | ||
| - seccomp:unconfined | ||
|
|
||
| # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. | ||
| # (Adding the "ports" property to this file will not forward from a Codespace.) | ||
|
|
||
| localstack: | ||
| image: localstack/localstack |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # To get started with Dependabot version updates, you'll need to specify which | ||
| # package ecosystems to update and where the package manifests are located. | ||
| # Please see the documentation for more information: | ||
| # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
| # https://containers.dev/guide/dependabot | ||
|
|
||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: "devcontainers" | ||
| directory: "/" | ||
| schedule: | ||
| interval: weekly |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/swiftlang/sourcekit-lsp/refs/heads/release/6.1/config.schema.json" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 6.2.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ public actor BreezeLambdaAPI<T: BreezeCodable>: Service { | |
| let timeout: TimeAmount | ||
| private let serviceGroup: ServiceGroup | ||
| private let apiConfig: any APIConfiguring | ||
| private let dynamoDBService: BreezeDynamoDBService | ||
|
|
||
| /// Initializes the BreezeLambdaAPI with the provided API configuration. | ||
| /// - Parameter apiConfig: An object conforming to `APIConfiguring` that provides the necessary configuration for the Breeze API. | ||
|
|
@@ -63,19 +64,18 @@ public actor BreezeLambdaAPI<T: BreezeCodable>: Service { | |
| logger: logger | ||
| ) | ||
| let operation = try apiConfig.operation() | ||
| let dynamoDBService = await BreezeDynamoDBService( | ||
| self.dynamoDBService = BreezeDynamoDBService( | ||
| config: config, | ||
| httpConfig: httpConfig, | ||
| logger: logger | ||
| ) | ||
| let breezeLambdaService = BreezeLambdaService<T>( | ||
| dynamoDBService: dynamoDBService, | ||
| operation: operation, | ||
| logger: logger | ||
| ) | ||
| let dbManager = dynamoDBService.dbManager | ||
| let breezeApi = BreezeLambdaHandler<T>(dbManager: dbManager, operation: operation) | ||
| let runtime = LambdaRuntime(body: breezeApi.handle) | ||
| self.serviceGroup = ServiceGroup( | ||
| services: [breezeLambdaService], | ||
| gracefulShutdownSignals: [.sigterm, .sigint], | ||
| services: [runtime, dynamoDBService], | ||
| gracefulShutdownSignals: [.sigint], | ||
| cancellationSignals: [.sigterm], | ||
| logger: logger | ||
| ) | ||
| } catch { | ||
|
|
@@ -90,7 +90,13 @@ public actor BreezeLambdaAPI<T: BreezeCodable>: Service { | |
| /// The internal ServiceGroup will handle the lifecycle of the BreezeLambdaAPI, including starting and stopping the service gracefully. | ||
| public func run() async throws { | ||
| logger.info("Starting BreezeLambdaAPI...") | ||
| try await serviceGroup.run() | ||
| do { | ||
| try await serviceGroup.run() | ||
| } catch { | ||
| try dynamoDBService.syncShutdown() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the life cycle group must do that. You should not shutdown() or cancel() a service part of the group There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it does unless there is a failure condition. Without this |
||
| logger.error("BreezeLambdaAPI failed with error: \(error.localizedDescription)") | ||
| throw error | ||
| } | ||
| logger.info("BreezeLambdaAPI is stopped successfully") | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you shutting down immediately at run() ? Does it work ? Why ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
try await gracefulShutdown()waits until graceful shutdown is triggered as documented in ServiceLifecyclehttps://swiftpackageindex.com/swift-server/swift-service-lifecycle/main/documentation/servicelifecycle/gracefulshutdown()