@@ -125,52 +125,41 @@ static int _ModelRunCtx_SetParams(RedisModuleCtx *ctx, RedisModuleString **inkey
125125int ParseModelRunCommand (RedisAI_RunInfo * rinfo , RedisModuleCtx * ctx , RedisModuleString * * argv ,
126126 int argc ) {
127127
128+ RAI_DagOp * currentOp ;
129+ RAI_InitDagOp (& currentOp );
130+ rinfo -> dagOps = array_append (rinfo -> dagOps , currentOp );
131+
128132 // Build a ModelRunCtx from command.
129- RAI_Error error = {0 };
130133 RAI_Model * model ;
131- RedisModuleString * * inkeys = array_new (RedisModuleString * , 1 );
132- RedisModuleString * * outkeys = array_new (RedisModuleString * , 1 );
133- RedisModuleString * runkey = NULL ;
134- RAI_ModelRunCtx * mctx = NULL ;
135- RAI_DagOp * currentOp ;
136134
137135 long long timeout = 0 ;
138- if (_ModelRunCommand_ParseArgs (ctx , argv , argc , & model , & error , & inkeys , & outkeys , & runkey ,
136+ if (_ModelRunCommand_ParseArgs (ctx , argv , argc , & model , currentOp -> err , & currentOp -> inkeys ,
137+ & currentOp -> outkeys , & currentOp -> runkey ,
139138 & timeout ) == REDISMODULE_ERR ) {
140- RedisModule_ReplyWithError (ctx , RAI_GetErrorOneLine (& error ));
139+ RedisModule_ReplyWithError (ctx , RAI_GetErrorOneLine (currentOp -> err ));
140+ goto cleanup ;
141+ }
142+
143+ if (timeout > 0 && !rinfo -> single_op_dag ) {
144+ RedisModule_ReplyWithError (ctx , "ERR TIMEOUT not allowed within a DAG command" );
141145 goto cleanup ;
142146 }
143- mctx = RAI_ModelRunCtxCreate (model );
144147
148+ RAI_ModelRunCtx * mctx = RAI_ModelRunCtxCreate (model );
145149 if (rinfo -> single_op_dag ) {
146150 rinfo -> timeout = timeout ;
147151 // Set params in ModelRunCtx, bring inputs from key space.
148- if (_ModelRunCtx_SetParams (ctx , inkeys , outkeys , mctx ) == REDISMODULE_ERR )
152+ if (_ModelRunCtx_SetParams (ctx , currentOp -> inkeys , currentOp -> outkeys , mctx ) ==
153+ REDISMODULE_ERR )
149154 goto cleanup ;
150155 }
151- if (RAI_InitDagOp (& currentOp ) == REDISMODULE_ERR ) {
152- RedisModule_ReplyWithError (
153- ctx , "ERR Unable to allocate the memory and initialise the RAI_dagOp structure" );
154- goto cleanup ;
155- }
156+
156157 currentOp -> commandType = REDISAI_DAG_CMD_MODELRUN ;
157- Dag_PopulateOp ( currentOp , mctx , inkeys , outkeys , runkey ) ;
158- rinfo -> dagOps = array_append ( rinfo -> dagOps , currentOp ) ;
158+ currentOp -> mctx = mctx ;
159+ currentOp -> devicestr = mctx -> model -> devicestr ;
159160 return REDISMODULE_OK ;
160161
161162cleanup :
162- for (size_t i = 0 ; i < array_len (inkeys ); i ++ ) {
163- RedisModule_FreeString (NULL , inkeys [i ]);
164- }
165- array_free (inkeys );
166- for (size_t i = 0 ; i < array_len (outkeys ); i ++ ) {
167- RedisModule_FreeString (NULL , outkeys [i ]);
168- }
169- array_free (outkeys );
170- if (runkey )
171- RedisModule_FreeString (NULL , runkey );
172- if (mctx )
173- RAI_ModelRunCtxFree (mctx );
174163 RAI_FreeRunInfo (rinfo );
175164 return REDISMODULE_ERR ;
176165}
@@ -293,55 +282,44 @@ static int _ScriptRunCtx_SetParams(RedisModuleCtx *ctx, RedisModuleString **inke
293282int ParseScriptRunCommand (RedisAI_RunInfo * rinfo , RedisModuleCtx * ctx , RedisModuleString * * argv ,
294283 int argc ) {
295284
285+ RAI_DagOp * currentOp ;
286+ RAI_InitDagOp (& currentOp );
287+ rinfo -> dagOps = array_append (rinfo -> dagOps , currentOp );
288+
296289 // Build a ScriptRunCtx from command.
297- RAI_Error error = {0 };
298290 RAI_Script * script ;
299- RedisModuleString * * inkeys = array_new (RedisModuleString * , 1 );
300- RedisModuleString * * outkeys = array_new (RedisModuleString * , 1 );
301- RedisModuleString * runkey = NULL ;
302291 const char * func_name = NULL ;
303- RAI_ScriptRunCtx * sctx = NULL ;
304- RAI_DagOp * currentOp ;
305292
306293 long long timeout = 0 ;
307294 int variadic = -1 ;
308- if (_ScriptRunCommand_ParseArgs (ctx , argv , argc , & script , & error , & inkeys , & outkeys , & runkey ,
309- & func_name , & timeout , & variadic ) == REDISMODULE_ERR ) {
310- RedisModule_ReplyWithError (ctx , RAI_GetErrorOneLine (& error ));
295+ if (_ScriptRunCommand_ParseArgs (ctx , argv , argc , & script , currentOp -> err , & currentOp -> inkeys ,
296+ & currentOp -> outkeys , & currentOp -> runkey , & func_name , & timeout ,
297+ & variadic ) == REDISMODULE_ERR ) {
298+ RedisModule_ReplyWithError (ctx , RAI_GetErrorOneLine (currentOp -> err ));
311299 goto cleanup ;
312300 }
313- sctx = RAI_ScriptRunCtxCreate (script , func_name );
301+ if (timeout > 0 && !rinfo -> single_op_dag ) {
302+ RedisModule_ReplyWithError (ctx , "ERR TIMEOUT not allowed within a DAG command" );
303+ goto cleanup ;
304+ }
305+
306+ RAI_ScriptRunCtx * sctx = RAI_ScriptRunCtxCreate (script , func_name );
314307 sctx -> variadic = variadic ;
315308
316309 if (rinfo -> single_op_dag ) {
317310 rinfo -> timeout = timeout ;
318311 // Set params in ScriptRunCtx, bring inputs from key space.
319- if (_ScriptRunCtx_SetParams (ctx , inkeys , outkeys , sctx ) == REDISMODULE_ERR )
312+ if (_ScriptRunCtx_SetParams (ctx , currentOp -> inkeys , currentOp -> outkeys , sctx ) ==
313+ REDISMODULE_ERR )
320314 goto cleanup ;
321315 }
322- if (RAI_InitDagOp (& currentOp ) == REDISMODULE_ERR ) {
323- RedisModule_ReplyWithError (
324- ctx , "ERR Unable to allocate the memory and initialise the RAI_dagOp structure" );
325- goto cleanup ;
326- }
316+ currentOp -> sctx = sctx ;
327317 currentOp -> commandType = REDISAI_DAG_CMD_SCRIPTRUN ;
328- Dag_PopulateOp ( currentOp , sctx , inkeys , outkeys , runkey ) ;
329- rinfo -> dagOps = array_append ( rinfo -> dagOps , currentOp );
318+ currentOp -> devicestr = sctx -> script -> devicestr ;
319+
330320 return REDISMODULE_OK ;
331321
332322cleanup :
333- for (size_t i = 0 ; i < array_len (inkeys ); i ++ ) {
334- RedisModule_FreeString (NULL , inkeys [i ]);
335- }
336- array_free (inkeys );
337- for (size_t i = 0 ; i < array_len (outkeys ); i ++ ) {
338- RedisModule_FreeString (NULL , outkeys [i ]);
339- }
340- array_free (outkeys );
341- if (runkey )
342- RedisModule_FreeString (NULL , runkey );
343- if (sctx )
344- RAI_ScriptRunCtxFree (sctx );
345323 RAI_FreeRunInfo (rinfo );
346324 return REDISMODULE_ERR ;
347325}
0 commit comments