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

Add cancelOn configuration #82

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

albertchae
Copy link
Collaborator

@albertchae albertchae commented Sep 11, 2024

Summary

Checklist

  • Update documentation
  • Added unit/integration tests

Related

Copy link

linear bot commented Sep 11, 2024

@albertchae albertchae force-pushed the albert/inn-3335-cancelOn-configuration branch from 4924958 to d32b38f Compare September 11, 2024 07:53
@albertchae albertchae requested a review from KiKoS0 September 11, 2024 07:55
.cancelOn("cancel", null, Duration.ofSeconds(6000))
.build("app-id", "https://mysite.com/api/inngest")

assertEquals<List<Cancellation>?>(listOf(Cancellation("cancel", null, "\"6000s\"")), durationConfig.cancel)
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 klaxon serializer for this adds inner quotes to the value

override fun toJson(value: Any): String = """"${(value as Duration).seconds}s""""
. I tried removing them and several tests broke, so I went with escaping them here.

@albertchae albertchae marked this pull request as ready for review September 11, 2024 08:08
@albertchae albertchae force-pushed the albert/inn-3335-cancelOn-configuration branch 2 times, most recently from b352beb to b4d1510 Compare September 13, 2024 00:49
- followed similar pattern to `InngestFunctionTriggers` but didn't reuse
  that class for a few reasons
  - `if` concept is similar but for triggers it gets serialized as
    `expression` but is `if` for cancel
  - `timeout` is only used by cancel and not for triggers and vice versa
    with `cron`, so it seems the `InngestFunctionTrigger` class's fields
    would be sparsely populated for all the concrete cases and not
    provide too much value in sharing code
  - While I like the idea of calling the "thing" that sets off Cancel as
    "CancelTrigger" or "CancellationTrigger", I thought this could be
    confusing since triggers are their own key under configuration
    https://github.com/inngest/inngest/blame/0ac11f2c312c066e517e53749052dd89fd2926ba/docs/SDK_SPEC.md#L478
- `Cancellation` name avoided "trigger" for reason above and followed
  pattern in https://github.com/inngest/inngest-js/blob/0e51903d5968a7287dd7e518bd5cc8acec3e6f3e/packages/inngest/src/types.ts#L901
- I originally was going to implement with `match` as well per
  https://www.inngest.com/docs/reference/typescript/functions/cancel-on,
  but I saw later that it's currently deprecated so I stuck to `if`
  only. https://github.com/inngest/inngest-js/blob/0e51903d5968a7287dd7e518bd5cc8acec3e6f3e/packages/inngest/src/types.ts#L946
- Per the flexibility of timeout in https://github.com/inngest/inngest/blob/0ac11f2c312c066e517e53749052dd89fd2926ba/docs/SDK_SPEC.md?plain=1#L580-L583
  The type for timeout is either `Duration` or `Instant`.
@albertchae albertchae force-pushed the albert/inn-3335-cancelOn-configuration branch from b4d1510 to 9698f55 Compare September 13, 2024 01:06
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.

nice work, i think it looks great

@albertchae albertchae merged commit ccddba0 into main Sep 13, 2024
9 checks passed
@albertchae albertchae deleted the albert/inn-3335-cancelOn-configuration branch September 13, 2024 01:51
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