-
-
Notifications
You must be signed in to change notification settings - Fork 937
feat(engine): run debounce system #2794
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
96c55cc
feat(engine): run debounce system
ericallam 57f45f1
support debounce options when batch triggering
ericallam 96680f0
fixed run engine delay tests
ericallam fb4138a
better delay calculations
ericallam 36cded7
better docs for options
ericallam f048420
debounce keys with a maximum size of 512
ericallam b115627
treat DELAYED execution status as an initiate state
ericallam f613c00
make it clear whats happening here
ericallam cddc7b6
fix deleting race condition using a lua script
ericallam b383a73
fix race condition when the delayUntil is updated while the enqueueDe…
ericallam 3bbee8c
Add an option for choosing the debounce mode, trailing or leading, wi…
ericallam 0d3bc3c
Fix TOCTOU Race Condition in registerDebouncedRun
ericallam f3f7355
remove the docs from this PR
ericallam d78877b
Fix new debounce run race
ericallam 20f3a88
better handle invalid debounce delay options
ericallam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@trigger.dev/sdk": patch | ||
| --- | ||
|
|
||
| feat(sdk): Support debouncing runs when triggering with new debounce options |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| description: how to create and apply database migrations | ||
| alwaysApply: false | ||
| --- | ||
|
|
||
| Follow our [migrations.md](mdc:ai/references/migrations.md) guide for how to create and apply database migrations. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| ## Creating and applying migrations | ||
|
|
||
| We use prisma migrations to manage the database schema. Please follow the following steps when editing the `internal-packages/database/prisma/schema.prisma` file: | ||
|
|
||
| Edit the `schema.prisma` file to add or modify the schema. | ||
|
|
||
| Create a new migration file but don't apply it yet: | ||
|
|
||
| ```bash | ||
| cd internal-packages/database | ||
| pnpm run db:migrate:dev:create --name "add_new_column_to_table" | ||
| ``` | ||
|
|
||
| The migration file will be created in the `prisma/migrations` directory, but it will have a bunch of edits to the schema that are not needed and will need to be removed before we can apply the migration. Here's an example of what the migration file might look like: | ||
|
|
||
| ```sql | ||
| -- AlterEnum | ||
| ALTER TYPE "public"."TaskRunExecutionStatus" ADD VALUE 'DELAYED'; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."TaskRun" ADD COLUMN "debounce" JSONB; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_BackgroundWorkerToBackgroundWorkerFile" ADD CONSTRAINT "_BackgroundWorkerToBackgroundWorkerFile_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_BackgroundWorkerToBackgroundWorkerFile_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_BackgroundWorkerToTaskQueue" ADD CONSTRAINT "_BackgroundWorkerToTaskQueue_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_BackgroundWorkerToTaskQueue_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_TaskRunToTaskRunTag" ADD CONSTRAINT "_TaskRunToTaskRunTag_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_TaskRunToTaskRunTag_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_WaitpointRunConnections" ADD CONSTRAINT "_WaitpointRunConnections_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_WaitpointRunConnections_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_completedWaitpoints" ADD CONSTRAINT "_completedWaitpoints_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_completedWaitpoints_AB_unique"; | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "SecretStore_key_idx" ON "public"."SecretStore"("key" text_pattern_ops); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "TaskRun_runtimeEnvironmentId_id_idx" ON "public"."TaskRun"("runtimeEnvironmentId", "id" DESC); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "TaskRun_runtimeEnvironmentId_createdAt_idx" ON "public"."TaskRun"("runtimeEnvironmentId", "createdAt" DESC); | ||
| ``` | ||
|
|
||
| All the following lines should be removed: | ||
|
|
||
| ```sql | ||
| -- AlterTable | ||
| ALTER TABLE "public"."_BackgroundWorkerToBackgroundWorkerFile" ADD CONSTRAINT "_BackgroundWorkerToBackgroundWorkerFile_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_BackgroundWorkerToBackgroundWorkerFile_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_BackgroundWorkerToTaskQueue" ADD CONSTRAINT "_BackgroundWorkerToTaskQueue_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_BackgroundWorkerToTaskQueue_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_TaskRunToTaskRunTag" ADD CONSTRAINT "_TaskRunToTaskRunTag_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_TaskRunToTaskRunTag_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_WaitpointRunConnections" ADD CONSTRAINT "_WaitpointRunConnections_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_WaitpointRunConnections_AB_unique"; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."_completedWaitpoints" ADD CONSTRAINT "_completedWaitpoints_AB_pkey" PRIMARY KEY ("A", "B"); | ||
|
|
||
| -- DropIndex | ||
| DROP INDEX "public"."_completedWaitpoints_AB_unique"; | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "SecretStore_key_idx" ON "public"."SecretStore"("key" text_pattern_ops); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "TaskRun_runtimeEnvironmentId_id_idx" ON "public"."TaskRun"("runtimeEnvironmentId", "id" DESC); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "TaskRun_runtimeEnvironmentId_createdAt_idx" ON "public"."TaskRun"("runtimeEnvironmentId", "createdAt" DESC); | ||
| ``` | ||
|
|
||
| Leaving only this: | ||
|
|
||
| ```sql | ||
| -- AlterEnum | ||
| ALTER TYPE "public"."TaskRunExecutionStatus" ADD VALUE 'DELAYED'; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "public"."TaskRun" ADD COLUMN "debounce" JSONB; | ||
| ``` | ||
|
|
||
| After editing the migration file, apply the migration: | ||
|
|
||
| ```bash | ||
| cd internal-packages/database | ||
| pnpm run db:migrate:deploy && pnpm run generate | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.