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

Application builder #224

Merged
merged 15 commits into from
Aug 16, 2023
Merged

Application builder #224

merged 15 commits into from
Aug 16, 2023

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Aug 14, 2023

Split HBApplication into

  • HBApplicationBuilder that is used to build up your application.
  • HBApplication which is the Service to run.
  • HBApplication.Context which is the context passed around with the request.

Splitting the application into building phase and running phase types means I can have an immutable and Sendable running application.
The context has been split out as it is not possible to create a server as a member of the application which requires the application to initialise it. It also gives us more control over what we pass around.
The other thing to note is this PR also disable the ability to extend the application through HBExtensions

@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Patch coverage: 86.48% and project coverage change: -0.30% ⚠️

Comparison is base (3ef0b25) 80.05% compared to head (5e1337a) 79.76%.

Additional details and impacted files
@@            Coverage Diff             @@
##            2.x.x     #224      +/-   ##
==========================================
- Coverage   80.05%   79.76%   -0.30%     
==========================================
  Files          97       96       -1     
  Lines        5947     5855      -92     
==========================================
- Hits         4761     4670      -91     
+ Misses       1186     1185       -1     
Files Changed Coverage Δ
...bird/AsyncAwaitSupport/Request+Persist+async.swift 100.00% <ø> (ø)
...s/Hummingbird/AsyncAwaitSupport/Router+async.swift 80.43% <0.00%> (ø)
Sources/Hummingbird/Codable/CodableProtocols.swift 70.00% <ø> (ø)
Sources/Hummingbird/Configuration.swift 68.75% <ø> (ø)
Sources/Hummingbird/Storage/PersistDriver.swift 85.71% <ø> (-6.60%) ⬇️
...ummingbirdFoundation/Codable/JSON/JSONCoding.swift 94.44% <ø> (ø)
...Codable/URLEncodedForm/URLEncodedFormDecoder.swift 64.62% <ø> (ø)
...Codable/URLEncodedForm/URLEncodedFormEncoder.swift 63.48% <ø> (ø)
Sources/HummingbirdJobs/JobQueue.swift 0.00% <ø> (ø)
Sources/HummingbirdJobs/JobQueueHandler.swift 0.00% <ø> (ø)
... and 14 more

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}]
} else {
self.additionalChannelHandlers = []
public init(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need for users to be able to initialize an HBApplication.Context?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used by the XCT framework. If we were requiring swift 5.9 I guess I could use package scope

.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.7.0"),
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.20.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.14.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.9.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.18.0"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason for the specific minor increase? The newest one is 1.19.0

Copy link
Member Author

@adam-fowler adam-fowler Aug 15, 2023

Choose a reason for hiding this comment

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

1.18.0 introduces NIOTSEventLoopGroup.singleton. Means I don't need to provide the ability to create a new EventLoopGroup (which involves managing its lifecycle) I just provide the option of .singleton instead.


// MARK: Methods

__consuming public func build() -> HBApplication {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we expect __consuming to stably stick around in/after 5.9?

Copy link
Member Author

Choose a reason for hiding this comment

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

The stdlib is full of functions labelled __consuming. I added it because I was thinking of making the builder a move only type, so once it had built the application it was consumed and unavailable

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense to me, and I really like it. I'm just worried that it might not be supported down the line.

Sources/Hummingbird/Storage/Application+Persist.swift Outdated Show resolved Hide resolved
Sources/HummingbirdJobs/Request+Jobs.swift Outdated Show resolved Hide resolved
Sources/HummingbirdXCT/ApplicationBuilder+XCT.swift Outdated Show resolved Hide resolved
Sources/HummingbirdXCT/HBXCTApplication.swift Outdated Show resolved Hide resolved
Sources/HummingbirdXCT/HBXCTRouter.swift Outdated Show resolved Hide resolved
Tests/HummingbirdTests/ExtensionTests.swift Outdated Show resolved Hide resolved
- Deleted commented out code
- FileMiddleware doesn't need an application to be constructed
- `HBApplicationBulder.buildAndTest` returns value returned by closure
Copy link
Contributor

@Joannis Joannis left a comment

Choose a reason for hiding this comment

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

I have some small open concerns, but nothing that should immediately prevent a merge

/// }
/// app.buildAndTest(.router) { client in
/// // does my app return "hello" in the body for this route
/// app.XCTExecute(uri: "/hello", method: .GET) { response in
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be client.XCTExecute?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch

@adam-fowler adam-fowler merged commit 0fb3f59 into 2.x.x Aug 16, 2023
4 of 5 checks passed
@adam-fowler adam-fowler deleted the application-builder branch August 16, 2023 12:37
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.

None yet

2 participants