Variants working in the new internal job system

This commit is contained in:
Eric Allam
2023-05-05 16:46:38 +01:00
parent 6d7f20b527
commit 0a7ad96dcc
4 changed files with 33 additions and 7 deletions
@@ -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",
+7 -1
View File
@@ -106,7 +106,13 @@ function buildRepoWebhookTrigger<TEvent>(
eventRule: {
event,
source: "github.com",
payload: filter ?? {},
payload: {
...(filter ?? {}),
repository: {
...filter?.repository,
full_name: [params.repo],
},
},
},
});
}
+10 -5
View File
@@ -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;
}