| 2486 | } |
| 2487 | |
| 2488 | static PyObject* DAGAddScriptRun(PyObject *self, PyObject *args, PyObject *kargs) { |
| 2489 | verifyRedisAILoaded(); |
| 2490 | PyDAGRunner *pyDag = (PyDAGRunner *)self; |
| 2491 | if(!_IsDagAPISupported(RedisAI_DAGCreateScriptRunOp) || !_IsValidDag(pyDag)) { |
| 2492 | return NULL; |
| 2493 | } |
| 2494 | |
| 2495 | PyObject* scriptName = GearsPyDict_GetItemString(kargs, "name"); |
| 2496 | if (!scriptName) { |
| 2497 | PyErr_SetString(GearsError, "Script key name was not given"); |
| 2498 | return NULL; |
| 2499 | } |
| 2500 | if(!PyUnicode_Check(scriptName)){ |
| 2501 | PyErr_SetString(GearsError, "Script name argument must be a string"); |
| 2502 | return NULL; |
| 2503 | } |
| 2504 | PyObject* funcName = GearsPyDict_GetItemString(kargs, "func"); |
| 2505 | if (!funcName) { |
| 2506 | PyErr_SetString(GearsError, "Function name was not given"); |
| 2507 | return NULL; |
| 2508 | } |
| 2509 | if(!PyUnicode_Check(funcName)){ |
| 2510 | PyErr_SetString(GearsError, "Function name argument must be a string"); |
| 2511 | return NULL; |
| 2512 | } |
| 2513 | const char* scriptNameStr = PyUnicode_AsUTF8AndSize(scriptName, NULL); |
| 2514 | const char* functionNameStr = PyUnicode_AsUTF8AndSize(funcName, NULL); |
| 2515 | |
| 2516 | // Create SCRIPTRUN op after bringing script from keyspace (raise an exception if it does not exist) |
| 2517 | RAI_Error *err; |
| 2518 | RedisAI_InitError(&err); |
| 2519 | RAI_DAGRunOp *scriptRunOp = _createScriptRunOp(scriptNameStr, functionNameStr, err); |
| 2520 | if (scriptRunOp == NULL) { |
| 2521 | RedisAI_FreeError(err); |
| 2522 | return NULL; |
| 2523 | } |
| 2524 | PyObject *ret = NULL; |
| 2525 | |
| 2526 | // Add to the scriptRun op with its inputs and output keys and insert it to the DAG |
| 2527 | PyObject* scriptInputs = GearsPyDict_GetItemString(kargs, "inputs"); |
| 2528 | PyObject* inputsIter = NULL; |
| 2529 | PyObject* scriptOutputs = NULL; |
| 2530 | PyObject* outputsIter = NULL; |
| 2531 | if (scriptInputs) { |
| 2532 | inputsIter = PyObject_GetIter(scriptInputs); |
| 2533 | if(!inputsIter) { |
| 2534 | PyErr_SetString(GearsError, "Script inputs must be iterable"); |
| 2535 | goto cleanup; |
| 2536 | } |
| 2537 | PyObject* input; |
| 2538 | while((input = (PyObject*)PyIter_Next(inputsIter)) != NULL) { |
| 2539 | if(!PyUnicode_Check(input)){ |
| 2540 | PyErr_SetString(GearsError, "Input name must be a string"); |
| 2541 | goto cleanup; |
| 2542 | } |
| 2543 | const char* inputStr = PyUnicode_AsUTF8AndSize(input, NULL); |
| 2544 | RedisAI_DAGRunOpAddInput(scriptRunOp, inputStr); |
| 2545 | } |
nothing calls this directly
no test coverage detected