Skip to content

Commit

Permalink
[ENG-6866] schedule child functions from parent component (#27800)
Browse files Browse the repository at this point in the history
scheduled jobs have a component & udf path which is for the function that is scheduled to run. separately, they were scheduled from a component which may be different.

GitOrigin-RevId: 4b3de87f80bac38f6ee7f2c78cd8b5d944db9706
  • Loading branch information
ldanilek authored and Convex, Inc. committed Jul 12, 2024
1 parent 7dd6cdb commit ecfc769
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/server/impl/actions_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ function syscallArgs(
functionReference: any,
args?: Record<string, Value>,
) {
const address = getFunctionAddress(functionReference);
return {
...address,
args: convexToJson(parseArgs(args)),
version,
requestId,
};
}

export function getFunctionAddress(functionReference: any) {
// The `run*` syscalls expect either a UDF path at "name" or a serialized
// reference at "reference". Dispatch on `functionReference` to coerce
// it to one ore the other.
Expand All @@ -32,12 +42,7 @@ function syscallArgs(
}
functionAddress = { reference: referencePath };
}
return {
...functionAddress,
args: convexToJson(parseArgs(args)),
version,
requestId,
};
return functionAddress;
}

export function setupActionCalls(requestId: string) {
Expand Down
10 changes: 5 additions & 5 deletions src/server/impl/scheduler_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { version } from "../../index.js";
import { performAsyncSyscall } from "./syscall.js";
import { parseArgs } from "../../common/index.js";
import { SchedulableFunctionReference, Scheduler } from "../scheduler.js";
import { getFunctionName } from "../../server/api.js";
import { Id } from "../../values/value.js";
import { validateArg } from "./validate.js";
import { getFunctionAddress } from "./actions_impl.js";

export function setupMutationScheduler(): Scheduler {
return {
Expand Down Expand Up @@ -84,11 +84,11 @@ function runAfterSyscallArgs(
throw new Error("`delayMs` must be non-negative");
}
const functionArgs = parseArgs(args);
const name = getFunctionName(functionReference);
const address = getFunctionAddress(functionReference);
// Note the syscall expects a unix timestamp, measured in seconds.
const ts = (Date.now() + delayMs) / 1000.0;
return {
name,
...address,
ts,
args: convexToJson(functionArgs),
version,
Expand All @@ -110,10 +110,10 @@ function runAtSyscallArgs(
} else {
throw new Error("The invoke time must a Date or a timestamp");
}
const name = getFunctionName(functionReference);
const address = getFunctionAddress(functionReference);
const functionArgs = parseArgs(args);
return {
name,
...address,
ts,
args: convexToJson(functionArgs),
version,
Expand Down

0 comments on commit ecfc769

Please sign in to comment.