Skip to content

#2250 dragonfruit #2360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/webapp/app/routes/resources.runs.$runParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
version: run.lockedToVersion?.version,
parentTaskRunId: run.parentTaskRun?.friendlyId ?? undefined,
rootTaskRunId: run.rootTaskRun?.friendlyId ?? undefined,
concurrencyKey: run.concurrencyKey ?? undefined,
},
queue: {
name: run.queue,
Expand Down
2 changes: 2 additions & 0 deletions apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,7 @@ export const AttemptForExecutionGetPayload = {
baseCostInCents: true,
maxDurationInSeconds: true,
tags: true,
concurrencyKey: true,
},
},
queue: {
Expand Down Expand Up @@ -1722,6 +1723,7 @@ class SharedQueueTasks {
baseCostInCents: taskRun.baseCostInCents,
metadata,
maxDuration: taskRun.maxDurationInSeconds ?? undefined,
concurrencyKey: taskRun.concurrencyKey ?? undefined,
},
queue: {
id: queue.friendlyId,
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/app/v3/services/createTaskRunAttempt.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class CreateTaskRunAttemptService extends BaseService {
version: lockedBy.worker.version,
metadata,
maxDuration: taskRun.maxDurationInSeconds ?? undefined,
concurrencyKey: taskRun.concurrencyKey ?? undefined,
},
queue: {
id: queue.friendlyId,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/v3/schemas/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const TaskRun = z.object({
/** The priority of the run. Wih a value of 10 it will be dequeued before runs that were triggered 9 seconds before it (assuming they had no priority set). */
priority: z.number().optional(),
baseCostInCents: z.number().optional(),
concurrencyKey: z.string().optional(),

parentTaskRunId: z.string().optional(),
rootTaskRunId: z.string().optional(),
Expand Down Expand Up @@ -375,6 +376,7 @@ export const V3TaskRun = z.object({
durationMs: z.number(),
costInCents: z.number(),
baseCostInCents: z.number(),
concurrencyKey: z.string().optional(),
});

export type V3TaskRun = z.infer<typeof V3TaskRun>;
Expand Down
26 changes: 25 additions & 1 deletion packages/core/test/taskExecutor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,28 @@ describe("TaskExecutor", () => {
});
});

test("should include concurrencyKey in task context", async () => {
let capturedContext: any;

const task = {
id: "test-task",
fns: {
run: async (payload: any, params: RunFnParams<any>) => {
capturedContext = params.ctx;
return {
output: "test-output",
};
},
},
};

const result = await executeTask(task, { test: "data" }, undefined, undefined, "user-123");

expect(result.result.ok).toBe(true);
expect(capturedContext).toBeDefined();
expect(capturedContext.run.concurrencyKey).toBe("user-123");
});

test("should handle middleware errors correctly", async () => {
const executionOrder: string[] = [];
const expectedError = new Error("Middleware error");
Expand Down Expand Up @@ -1846,7 +1868,8 @@ function executeTask(
task: TaskMetadataWithFunctions,
payload: any,
signal?: AbortSignal,
retrySettings?: RetryOptions
retrySettings?: RetryOptions,
concurrencyKey?: string
) {
const tracingSDK = new TracingSDK({
url: "http://localhost:4318",
Expand Down Expand Up @@ -1904,6 +1927,7 @@ function executeTask(
baseCostInCents: 0,
priority: 0,
maxDuration: 1000,
concurrencyKey: concurrencyKey,
},
machine: {
name: "micro",
Expand Down