Variants working in the new internal job system
This commit is contained in:
@@ -383,6 +383,14 @@ export class RegisterJobService {
|
||||
},
|
||||
update: {
|
||||
data: trigger,
|
||||
eventRule: {
|
||||
update: {
|
||||
event: trigger.eventRule.event,
|
||||
source: trigger.eventRule.source,
|
||||
payloadFilter: trigger.eventRule.payload,
|
||||
contextFilter: trigger.eventRule.context,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,7 +35,14 @@ new Job({
|
||||
channel: "C04GWUTDC3W",
|
||||
});
|
||||
},
|
||||
}).attachTo(client);
|
||||
})
|
||||
.attachTo(client)
|
||||
.attachVariant(
|
||||
"ericallam/hello-world",
|
||||
gh.triggers.onIssueOpened({
|
||||
repo: "ericallam/hello-world",
|
||||
})
|
||||
);
|
||||
|
||||
new Job({
|
||||
id: "alert-on-new-github-issues-2",
|
||||
|
||||
@@ -106,7 +106,13 @@ function buildRepoWebhookTrigger<TEvent>(
|
||||
eventRule: {
|
||||
event,
|
||||
source: "github.com",
|
||||
payload: filter ?? {},
|
||||
payload: {
|
||||
...(filter ?? {}),
|
||||
repository: {
|
||||
...filter?.repository,
|
||||
full_name: [params.repo],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ export class Job<
|
||||
readonly options: JobOptions<TTrigger, TConnections>;
|
||||
|
||||
client?: TriggerClient;
|
||||
#pendingVariants: Array<{ id: string; trigger: TTrigger }> = [];
|
||||
|
||||
constructor(options: JobOptions<TTrigger, TConnections>) {
|
||||
this.options = options;
|
||||
@@ -91,18 +92,22 @@ export class Job<
|
||||
|
||||
client.attach(this);
|
||||
|
||||
if (this.#pendingVariants.length > 0) {
|
||||
this.#pendingVariants.forEach(({ id, trigger }) => {
|
||||
client.attachVariant(this, id, trigger);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
attachVariant(id: string, trigger: TTrigger) {
|
||||
if (!this.client) {
|
||||
throw new Error(
|
||||
`Job "${this.id}" has not been registered with a client.`
|
||||
);
|
||||
this.#pendingVariants.push({ id, trigger });
|
||||
} else {
|
||||
this.client.attachVariant(this, id, trigger);
|
||||
}
|
||||
|
||||
this.client.attachVariant(this, id, trigger);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user