Skip to content

[TRI-1132] Add a deduplicationKey to Tasks #384

Description

@matt-aitken

What is it?

Sometimes you only want a Task to run once across your entire Project/Job.

One example is sending non-recurring emails. This should only ever happen exactly once.

await io.resend.sendEmail("welcome-email", {
  to: user.email,
  subject: "Welcome to Trigger.dev!",
  react: <WelcomeEmail user={user} />,
  from: "Trigger.dev <hello@email.trigger.dev>",
}, {
  deduplicationKey: `welcome-email-${user.id}`,
  //optional and defaults to "project", but can be "job" or "organization" as well
  deduplicationScope: "project"
});

It would be impossible to have another Task run with the same deduplicationKey inside a project in this case.

If you specified the scope to be "job" or "organization" it would deduplicate at that scope instead.

If it has already run a Task with the same dedupe key it would return the data, just like the key does.

Implementation

  1. Add a deduplicationKey column to the Task table which is a unique String, required, and defaults to a cuid. Migration needs to add unique ids to all existing Tasks.
  2. Add SDK support to runTask
  3. On the server it would prepend the proj:${projectId}, org:${orgId}, job:${jobId} to the key before it's saved to the database. Also on lookup it needs to do the same.
  4. Roll out support to integrations

From SyncLinear.com | TRI-1132

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions