| 1523 | } |
| 1524 | |
| 1525 | static PyObject* run(PyObject *self, PyObject *args, PyObject *kargs){ |
| 1526 | PythonThreadCtx* ptctx = GetPythonThreadCtx(); |
| 1527 | PyFlatExecution* pfep = (PyFlatExecution*)self; |
| 1528 | |
| 1529 | if(ptctx->currentCtx && ptctx->createdExecution){ |
| 1530 | // we have currentCtx, which means we run inside rg.pyexecute command. |
| 1531 | // it is not possible to run 2 executions in single rg.pyexecute command. |
| 1532 | PyErr_SetString(GearsError, "Can not run more then 1 executions in a single script"); |
| 1533 | return NULL; |
| 1534 | } |
| 1535 | |
| 1536 | const char* defaultRegexStr = "*"; |
| 1537 | const char* patternStr = defaultRegexStr; |
| 1538 | void* arg; |
| 1539 | if (strcmp(RedisGears_GetReader(pfep->fep), "PythonReader") == 0){ |
| 1540 | if(PyTuple_Size(args) != 1){ |
| 1541 | PyErr_SetString(GearsError, "python reader function is not given"); |
| 1542 | return NULL; |
| 1543 | } |
| 1544 | arg = PyTuple_GetItem(args, 0); |
| 1545 | if(!PyObject_TypeCheck(arg, &PyFunction_Type)){ |
| 1546 | PyErr_SetString(GearsError, "pyreader argument must be a function"); |
| 1547 | return NULL; |
| 1548 | } |
| 1549 | Py_INCREF((PyObject*)arg); |
| 1550 | }else{ |
| 1551 | if(PyTuple_Size(args) > 0){ |
| 1552 | PyObject* pattern = PyTuple_GetItem(args, 0); |
| 1553 | if(!PyUnicode_Check(pattern)){ |
| 1554 | PyErr_SetString(GearsError, "regex argument must be a string"); |
| 1555 | return NULL; |
| 1556 | } |
| 1557 | patternStr = PyUnicode_AsUTF8AndSize(pattern, NULL); |
| 1558 | } |
| 1559 | if(strcmp(RedisGears_GetReader(pfep->fep), "StreamReader") == 0){ |
| 1560 | arg = runCreateStreamReaderArgs(patternStr, kargs); |
| 1561 | }else if(strcmp(RedisGears_GetReader(pfep->fep), "KeysReader") == 0){ |
| 1562 | arg = runCreateKeysReaderArgs(patternStr, kargs); |
| 1563 | }else{ |
| 1564 | PyErr_SetString(GearsError, "Given reader do not support run or not exists"); |
| 1565 | return NULL; |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | PyObject* pymode = GearsPyDict_GetItemString(kargs, "mode"); |
| 1570 | ExecutionMode mode = ExecutionModeAsync; |
| 1571 | if(pymode){ |
| 1572 | if(PyUnicode_Check(pymode)){ |
| 1573 | const char* modeStr = PyUnicode_AsUTF8AndSize(pymode, NULL); |
| 1574 | if(strcmp(modeStr, "async") == 0){ |
| 1575 | mode = ExecutionModeAsync; |
| 1576 | }else if(strcmp(modeStr, "async_local") == 0){ |
| 1577 | mode = ExecutionModeAsyncLocal; |
| 1578 | }else{ |
| 1579 | PyErr_SetString(GearsError, "unknown execution mode"); |
| 1580 | return NULL; |
| 1581 | } |
| 1582 | }else{ |
nothing calls this directly
no test coverage detected