-
Notifications
You must be signed in to change notification settings - Fork 3
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
Validate concurrency key is required when scope is account or env #81
Changes from all commits
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 |
---|---|---|
|
@@ -113,12 +113,20 @@ class InngestFunctionConfigBuilder { | |
key: String? = null, | ||
scope: ConcurrencyScope? = null, | ||
): InngestFunctionConfigBuilder { | ||
when (scope) { | ||
ConcurrencyScope.ENVIRONMENT -> if (key == null) throw InngestInvalidConfigurationException("Concurrency key required with environment scope") | ||
ConcurrencyScope.ACCOUNT -> if (key == null) throw InngestInvalidConfigurationException("Concurrency key required with account scope") | ||
Comment on lines
+117
to
+118
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. 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 see yeah that makes sense, the js sdk isn't preventing this either but it could probably prevent it better with a union type instead of exceptions. 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. yeah I was considering a similar idea but it seemed more cumbersome to do in kotlin, so I went with the validation method |
||
ConcurrencyScope.FUNCTION -> {} | ||
null -> {} | ||
Comment on lines
+119
to
+120
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. nit: can be a single else clause unless you wanted all expected values explicit. 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. yeah I was thinking of making it exhaustive but I could be convinced either way |
||
} | ||
|
||
val c = Concurrency(limit, key, scope) | ||
// TODO - Limit concurrency length to 2 | ||
if (this.concurrency == null) { | ||
this.concurrency = mutableListOf(c) | ||
} else if (this.concurrency!!.size == 2) { | ||
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. Now that i think of it Kotlin not inferring the non-null type is because different threads could mutate it to 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. huh interesting I was wondering why the compiler was realizing it wasn't null but that makes sense. Do you know a way around this? I tried wrapping this with a |
||
throw InngestInvalidConfigurationException("Maximum of 2 concurrency options allowed") | ||
} else { | ||
this.concurrency?.add(c) | ||
this.concurrency!!.add(c) | ||
} | ||
return this | ||
} | ||
|
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.
this is unnecessary because it's being thrown here
inngest-kt/inngest/src/main/kotlin/com/inngest/InngestFunctionConfigBuilder.kt
Lines 210 to 212 in 70ac4e3
and
catch (e: Exception)
was swallowing otherInngestInvalidConfigurationException
s and rethrowing them for the wrong reason