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

Refactor HttpClient to its own class #29

Merged
merged 5 commits into from
Feb 25, 2024
Merged

Conversation

KiKoS0
Copy link
Collaborator

@KiKoS0 KiKoS0 commented Feb 25, 2024

Refactors API calls into a separate HttpClient class.
Making its headers fully configurable by the Inngest client.

It should also be able to pool network connections correctly given
that it's the same instance. According to: https://square.github.io/okhttp/contribute/concurrency/#connection-pool

Which makes its headers fully configurable by the Inngest client.
It should also be able to pool network connections correctly given
that it's the same instance. According to:

https://square.github.io/okhttp/contribute/concurrency/#connection-pool
Copy link
Contributor

@darwin67 darwin67 left a comment

Choose a reason for hiding this comment

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

One comment about the framework value but otherwise looks good.

}
class Inngest
@JvmOverloads
constructor(val appId: String, framework: String? = null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Framework needs to be inferred from the adapter and is never a value passed in on the constructor.

https://www.inngest.com/docs/reference/client/create

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense, I'll address it 👍

@darwin67
Copy link
Contributor

Or I can change it later as well, so you can merge as is if you want

It's now set to the `CommHandler` similarly to the other SDKs.
Copy link
Collaborator

@albertchae albertchae left a comment

Choose a reason for hiding this comment

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

solid improvement 🚀

InngestHeaderKey.Sdk.value to sdk,
InngestHeaderKey.UserAgent.value to sdk,
InngestHeaderKey.Framework.value to (framework?.value),
).filterValues { (it is String) }.entries.associate { (k, v) -> k to v!! }
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this to check for null values? Why is SupportedFrameworkName nullable anyway, could we make it not nullable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's nullable because the Inngest's client uses it and isn't provided the framework option as mentioned ☝️ by Darwin: inngest.com/docs/reference/client/create.

also looking at these two header generation functions in the other sdks, i think we'll have more optional headers implemented:

https://github.com/inngest/inngest-py/blob/2dd0ebd45c2fdbb035c03e0ec188567a54e76c31/inngest/_internal/client_lib.py#L137-L144
https://github.com/inngest/inngest-js/blob/1b9f101ca6cd310e429cebcf8bceaf2faf309624/packages/inngest/src/helpers/env.ts#L297-L301

Copy link
Collaborator

Choose a reason for hiding this comment

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

fair enough, I guess it's possible people will want to use the Inngest client directly without a framework adapter

inngest-core/src/main/kotlin/com/inngest/HttpClient.kt Outdated Show resolved Hide resolved
): T? {
val request = httpClient.build(url, payload)

return httpClient.send(request) lambda@{ response ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it's possible to restructure the SDK to use these to manipulate control flow instead of exceptions. We can consider it later since things work as is

@KiKoS0 KiKoS0 merged commit c6eccd4 into main Feb 25, 2024
7 checks passed
@KiKoS0 KiKoS0 deleted the refactor-inngest-http-client branch February 25, 2024 21:01
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.

3 participants