v3: Support triggering tasks with non-URL friendly characters in the ID

This commit is contained in:
Eric Allam
2024-05-31 11:39:17 +01:00
parent 51bb4c887a
commit b4f9b70ae2
4 changed files with 31 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---
Support triggering tasks with non-URL friendly characters in the ID
+6 -2
View File
@@ -111,9 +111,11 @@ export class ApiClient {
}
triggerTask(taskId: string, body: TriggerTaskRequestBody, options?: TriggerOptions) {
const encodedTaskId = encodeURIComponent(taskId);
return zodfetch(
TriggerTaskResponse,
`${this.baseUrl}/api/v1/tasks/${taskId}/trigger`,
`${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`,
{
method: "POST",
headers: this.#getHeaders(options?.spanParentAsLink ?? false),
@@ -124,9 +126,11 @@ export class ApiClient {
}
batchTriggerTask(taskId: string, body: BatchTriggerTaskRequestBody, options?: TriggerOptions) {
const encodedTaskId = encodeURIComponent(taskId);
return zodfetch(
BatchTriggerTaskResponse,
`${this.baseUrl}/api/v1/tasks/${taskId}/batch`,
`${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`,
{
method: "POST",
headers: this.#getHeaders(options?.spanParentAsLink ?? false),
+13 -1
View File
@@ -4,6 +4,7 @@ import { createReadStream } from "node:fs";
import { firstScheduledTask } from "./trigger/scheduled";
import { simpleChildTask } from "./trigger/subtasks";
import { taskThatErrors } from "./trigger/retries";
import { unfriendlyIdTask } from "./trigger/other";
dotenv.config();
@@ -261,8 +262,19 @@ async function doScheduleLists() {
}
}
async function doTriggerUnfriendlyTaskId() {
const run = await unfriendlyIdTask.trigger();
console.log("unfriendly id task run", run);
const completedRun = await waitForRunToComplete(run.id);
console.log("completed run", completedRun);
}
// doRuns().catch(console.error);
doListRuns().catch(console.error);
// doListRuns().catch(console.error);
// doScheduleLists().catch(console.error);
// doSchedules().catch(console.error);
// doEnvVars().catch(console.error);
doTriggerUnfriendlyTaskId().catch(console.error);
@@ -75,3 +75,10 @@ export const consecutiveDependencyAndWait = task({
logger.log("logs after");
},
});
export const unfriendlyIdTask = task({
id: "hello/world:task-1",
run: async () => {
console.log("Hello world");
},
});