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

Validate concurrency key is required when scope is account or env #81

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

albertchae
Copy link
Collaborator

Summary

  • If concurrency scope is account or env, validate that key is provided
  • Also added check that at most 2 concurrency options are provided
  • Removed exception catch in InngestFunction.kt since it is swallowing
    other InngestInvalidConfigurationExceptions
  • Add key for RestoreFromGlacier example

Checklist

  • Update documentation
  • Added unit/integration tests

Related

Copy link

linear bot commented Sep 9, 2024

Comment on lines +117 to +118
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")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the ticket originally said function or env scope but dev server shows this

Screenshot 2024-09-09 at 8 22 02 AM
Screenshot 2024-09-09 at 8 20 49 AM

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Comment on lines -25 to -29
} catch (e: Exception) {
throw InngestInvalidConfigurationException(
"Function id must be configured via builder: ${this.javaClass.name}",
)
}
Copy link
Collaborator Author

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

if (id == null) {
throw InngestInvalidConfigurationException("Function id must be configured via builder")
}

and catch (e: Exception) was swallowing other InngestInvalidConfigurationExceptions and rethrowing them for the wrong reason

- If concurrency scope is account or env, validate that key is provided
- Also added check that at most 2 concurrency options are provided
- Removed exception catch in InngestFunction.kt since it is swallowing
  other InngestInvalidConfigurationExceptions
- Add key for RestoreFromGlacier example
@albertchae albertchae force-pushed the albert/inn-3354-concurrency-scope-validation branch from a458849 to b950969 Compare September 9, 2024 15:33
@inngest inngest deleted a comment from github-actions bot Sep 9, 2024
@inngest inngest deleted a comment from github-actions bot Sep 9, 2024
@albertchae albertchae marked this pull request as ready for review September 9, 2024 15:35
@albertchae albertchae requested a review from KiKoS0 September 9, 2024 15:35
Copy link
Collaborator

@KiKoS0 KiKoS0 left a comment

Choose a reason for hiding this comment

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

looks good

Comment on lines +119 to +120
ConcurrencyScope.FUNCTION -> {}
null -> {}
Copy link
Collaborator

@KiKoS0 KiKoS0 Sep 10, 2024

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

if (this.concurrency == null) {
this.concurrency = mutableListOf(c)
} else if (this.concurrency!!.size == 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 null between the null check and accessing it right? Similar to your other stepIdsToSeenCount[id] being still nullable as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 synchronized block and it doesn't seem to help 🤔

@albertchae
Copy link
Collaborator Author

@KiKoS0 going to merge as is but if you have additional opinions on the when cases and/or getting rid of the !!, I can address in a follow up

@albertchae albertchae merged commit 937f7af into main Sep 10, 2024
9 checks passed
@albertchae albertchae deleted the albert/inn-3354-concurrency-scope-validation branch September 10, 2024 02:46
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.

2 participants