This has been deprecated in favor of DynamicTrigger.register

Parameters

cacheKey
string
required

Should be a stable and unique cache key inside the run(). See resumability for more information.

dynamicTrigger
DynamicTrigger
required

A DynamicTrigger that will trigger any Jobs it’s attached.

id
string
required

A unique id for the registration. This is used to identify and unregister later.

params
object
required

The params for the DynamicTrigger. These will vary depending on the type of the DynamicTrigger.

Returns

A Promise that resolves to an object with the following fields:

id
string
required

A unique id for the registration. This is used to identify and unregister later.

key
string
required

The key of the registration.

Example

//1. create a DynamicTrigger
const dynamicOnIssueOpenedTrigger = client.defineDynamicTrigger({
  id: "github-issue-opened",
  event: events.onIssueOpened,
  source: github.sources.repo,
});

//2. create a Job that is attached to the dynamic trigger
client.defineJob({
  id: "listen-for-dynamic-trigger",
  name: "Listen for dynamic trigger",
  version: "0.1.1",
  trigger: dynamicOnIssueOpenedTrigger,
  integrations: {
    slack,
  },
  run: async (payload, io, ctx) => {
    await io.slack.postMessage("Slack πŸ“", {
      text: `New Issue opened on repo: ${payload.issue.html_url}. \n\n${JSON.stringify(ctx)}`,
      channel: "C04GWUTDC3W",
    });
  },
});

client.defineJob({
  id: "new-repo",
  name: "New repo",
  version: "0.1.1",
  trigger: github.triggers.org({
    event: events.onNewRepository,
    org: "triggerdotdev",
  }),
  run: async (payload, io, ctx) => {
    //3. Register the dynamic trigger so you get notified when an issue is opened
    return await io.registerTrigger(
      "register-repo",
      dynamicOnIssueOpenedTrigger,
      payload.repository.name,
      {
        owner: payload.repository.owner.login,
        repo: payload.repository.name,
      }
    );
  },
});