| 1940 | } |
| 1941 | |
| 1942 | static PyObject* registerExecution(PyObject *self, PyObject *args, PyObject *kargs){ |
| 1943 | PythonThreadCtx* ptctx = GetPythonThreadCtx(); |
| 1944 | PyFlatExecution* pfep = (PyFlatExecution*)self; |
| 1945 | |
| 1946 | PyObject* pymode = GearsPyDict_GetItemString(kargs, "mode"); |
| 1947 | ExecutionMode mode = ExecutionModeAsync; |
| 1948 | if(pymode){ |
| 1949 | if(PyUnicode_Check(pymode)){ |
| 1950 | const char* modeStr = PyUnicode_AsUTF8AndSize(pymode, NULL); |
| 1951 | if(strcmp(modeStr, "async") == 0){ |
| 1952 | mode = ExecutionModeAsync; |
| 1953 | }else if(strcmp(modeStr, "sync") == 0){ |
| 1954 | mode = ExecutionModeSync; |
| 1955 | }else if(strcmp(modeStr, "async_local") == 0){ |
| 1956 | mode = ExecutionModeAsyncLocal; |
| 1957 | }else{ |
| 1958 | PyErr_SetString(GearsError, "unknown execution mode"); |
| 1959 | return NULL; |
| 1960 | } |
| 1961 | }else{ |
| 1962 | PyErr_SetString(GearsError, "execution mode must be a string"); |
| 1963 | return NULL; |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | PyObject* onRegistered = GearsPyDict_GetItemString(kargs, "onRegistered"); |
| 1968 | if(onRegistered && onRegistered != Py_None){ |
| 1969 | if(!PyFunction_Check(onRegistered)){ |
| 1970 | PyErr_SetString(GearsError, "OnRegistered argument must be a function"); |
| 1971 | return NULL; |
| 1972 | } |
| 1973 | Py_INCREF(onRegistered); |
| 1974 | if(RGM_SetFlatExecutionOnRegisteredCallback(pfep->fep, RedisGearsPy_OnRegistered, onRegistered) != REDISMODULE_OK){ |
| 1975 | PyErr_SetString(GearsError, "Failed setting on OnRegistered callback"); |
| 1976 | GearsPyDecRef(onRegistered); |
| 1977 | return NULL; |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | void* executionArgs = registerCreateArgs(pfep->fep, kargs, mode); |
| 1982 | if(executionArgs == NULL){ |
| 1983 | return NULL; |
| 1984 | } |
| 1985 | |
| 1986 | char *err = NULL; |
| 1987 | char *registrationId = NULL; |
| 1988 | int status; |
| 1989 | if (ptctx->currSession->srctx) { |
| 1990 | status = RedisGears_PrepareForRegister(ptctx->currSession->srctx, pfep->fep, mode, executionArgs, &err, ®istrationId); |
| 1991 | } else { |
| 1992 | // we do not have session registration ctx, we will register and stand alone registration. |
| 1993 | status = RedisGears_RegisterFep(pluginCtx, pfep->fep, mode, executionArgs, &err, ®istrationId); |
| 1994 | } |
| 1995 | if(!status){ |
| 1996 | if(err){ |
| 1997 | PyErr_SetString(GearsError, err); |
| 1998 | RG_FREE(err); |
| 1999 | }else{ |
nothing calls this directly
no test coverage detected