@@ -8,19 +8,22 @@ import {
88import { v , VString } from "convex/values" ;
99import { Mounts } from "../component/_generated/api.js" ;
1010import {
11+ DEFAULT_LOG_LEVEL ,
12+ type LogLevel ,
13+ logLevel ,
14+ } from "../component/logging.js" ;
15+ import {
16+ Config ,
17+ DEFAULT_MAX_PARALLELISM ,
1118 OnComplete ,
12- runResult as runResultValidator ,
13- RunResult ,
19+ runResult as resultValidator ,
1420 type RetryBehavior ,
21+ RunResult ,
1522 OnCompleteArgs as SharedOnCompleteArgs ,
1623 Status ,
17- Config ,
1824} from "../component/shared.js" ;
19- import { type LogLevel , logLevel } from "../component/logging.js" ;
2025import { RunMutationCtx , RunQueryCtx , UseApi } from "./utils.js" ;
21- import { DEFAULT_LOG_LEVEL } from "../component/logging.js" ;
22- import { DEFAULT_MAX_PARALLELISM } from "../component/kick.js" ;
23- export { runResultValidator , type RunResult } ;
26+ export { resultValidator , type RunResult } ;
2427
2528// Attempts will run with delay [0, 250, 500, 1000, 2000] (ms)
2629export const DEFAULT_RETRY_BEHAVIOR : RetryBehavior = {
@@ -133,11 +136,18 @@ export class Workpool {
133136 fnArgs : Args ,
134137 options ?: CallbackOptions & SchedulerOptions
135138 ) : Promise < WorkId > {
139+ const onComplete : OnComplete | undefined = options ?. onComplete
140+ ? {
141+ fnHandle : await createFunctionHandle ( options . onComplete ) ,
142+ context : options . context ,
143+ }
144+ : undefined ;
136145 const id = await ctx . runMutation ( this . component . lib . enqueue , {
137146 ...( await defaultEnqueueArgs ( fn , this . options ) ) ,
138147 fnArgs,
139148 fnType : "mutation" ,
140149 runAt : getRunAt ( options ) ,
150+ onComplete,
141151 } ) ;
142152 return id as WorkId ;
143153 }
@@ -215,7 +225,7 @@ export type CallbackOptions = {
215225 * args: {
216226 * workId: workIdValidator,
217227 * context: v.any(),
218- * result: runResult ,
228+ * result: resultValidator ,
219229 * },
220230 * handler: async (ctx, args) => {
221231 * console.log(args.result, "Got Context back -> ", args.context, Date.now() - args.context);
0 commit comments