@@ -125,56 +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- if (error .detail ) {
163- RedisModule_Free (error .detail );
164- RedisModule_Free (error .detail_oneline );
165- }
166- for (size_t i = 0 ; i < array_len (inkeys ); i ++ ) {
167- RedisModule_FreeString (NULL , inkeys [i ]);
168- }
169- array_free (inkeys );
170- for (size_t i = 0 ; i < array_len (outkeys ); i ++ ) {
171- RedisModule_FreeString (NULL , outkeys [i ]);
172- }
173- array_free (outkeys );
174- if (runkey )
175- RedisModule_FreeString (NULL , runkey );
176- if (mctx )
177- RAI_ModelRunCtxFree (mctx );
178163 RAI_FreeRunInfo (rinfo );
179164 return REDISMODULE_ERR ;
180165}
@@ -287,56 +272,44 @@ static int _ScriptRunCtx_SetParams(RedisModuleCtx *ctx, RedisModuleString **inke
287272int ParseScriptRunCommand (RedisAI_RunInfo * rinfo , RedisModuleCtx * ctx , RedisModuleString * * argv ,
288273 int argc ) {
289274
275+ RAI_DagOp * currentOp ;
276+ RAI_InitDagOp (& currentOp );
277+ rinfo -> dagOps = array_append (rinfo -> dagOps , currentOp );
278+
290279 // Build a ScriptRunCtx from command.
291- RAI_Error error = {0 };
292280 RAI_Script * script ;
293- RedisModuleString * * inkeys = array_new (RedisModuleString * , 1 );
294- RedisModuleString * * outkeys = array_new (RedisModuleString * , 1 );
295- RedisModuleString * runkey = NULL ;
296281 const char * func_name = NULL ;
297- RAI_ScriptRunCtx * sctx = NULL ;
298- RAI_DagOp * currentOp ;
299282
300283 long long timeout = 0 ;
301284 int variadic = -1 ;
302- if (_ScriptRunCommand_ParseArgs (ctx , argv , argc , & script , & error , & inkeys , & outkeys , & runkey ,
303- & func_name , & timeout , & variadic ) == REDISMODULE_ERR ) {
304- RedisModule_ReplyWithError (ctx , RAI_GetErrorOneLine (& error ));
285+ if (_ScriptRunCommand_ParseArgs (ctx , argv , argc , & script , currentOp -> err , & currentOp -> inkeys ,
286+ & currentOp -> outkeys , & currentOp -> runkey , & func_name , & timeout ,
287+ & variadic ) == REDISMODULE_ERR ) {
288+ RedisModule_ReplyWithError (ctx , RAI_GetErrorOneLine (currentOp -> err ));
289+ goto cleanup ;
290+ }
291+ if (timeout > 0 && !rinfo -> single_op_dag ) {
292+ RedisModule_ReplyWithError (ctx , "ERR TIMEOUT not allowed within a DAG command" );
305293 goto cleanup ;
306294 }
307- sctx = RAI_ScriptRunCtxCreate (script , func_name );
295+
296+ RAI_ScriptRunCtx * sctx = RAI_ScriptRunCtxCreate (script , func_name );
308297 sctx -> variadic = variadic ;
309298
310299 if (rinfo -> single_op_dag ) {
311300 rinfo -> timeout = timeout ;
312301 // Set params in ScriptRunCtx, bring inputs from key space.
313- if (_ScriptRunCtx_SetParams (ctx , inkeys , outkeys , sctx ) == REDISMODULE_ERR )
302+ if (_ScriptRunCtx_SetParams (ctx , currentOp -> inkeys , currentOp -> outkeys , sctx ) ==
303+ REDISMODULE_ERR )
314304 goto cleanup ;
315305 }
316- RAI_InitDagOp (& currentOp );
317-
306+ currentOp -> sctx = sctx ;
318307 currentOp -> commandType = REDISAI_DAG_CMD_SCRIPTRUN ;
319- Dag_PopulateOp ( currentOp , sctx , inkeys , outkeys , runkey ) ;
320- rinfo -> dagOps = array_append ( rinfo -> dagOps , currentOp );
308+ currentOp -> devicestr = sctx -> script -> devicestr ;
309+
321310 return REDISMODULE_OK ;
322311
323312cleanup :
324- if (error .detail ) {
325- RedisModule_Free (error .detail );
326- RedisModule_Free (error .detail_oneline );
327- }
328- for (size_t i = 0 ; i < array_len (inkeys ); i ++ ) {
329- RedisModule_FreeString (NULL , inkeys [i ]);
330- }
331- array_free (inkeys );
332- for (size_t i = 0 ; i < array_len (outkeys ); i ++ ) {
333- RedisModule_FreeString (NULL , outkeys [i ]);
334- }
335- array_free (outkeys );
336- if (runkey )
337- RedisModule_FreeString (NULL , runkey );
338- if (sctx )
339- RAI_ScriptRunCtxFree (sctx );
340313 RAI_FreeRunInfo (rinfo );
341314 return REDISMODULE_ERR ;
342315}
0 commit comments