This is an automated email from the ASF dual-hosted git repository. szaszm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 66e465d9b9053cd2ad8c208611c84c329b7ac7d5 Author: Gabor Gyimesi <[email protected]> AuthorDate: Thu Sep 26 17:55:20 2024 +0200 MINIFICPP-2453 Add yield function support to python API Closes #1865 Signed-off-by: Marton Szasz <[email protected]> --- docker/test/integration/resources/python/CreateNothing.py | 1 + extensions/python/pythonprocessors/nifiapi/properties.py | 3 +++ extensions/python/types/PyProcessContext.cpp | 13 +++++++++++++ extensions/python/types/PyProcessContext.h | 1 + 4 files changed, 18 insertions(+) diff --git a/docker/test/integration/resources/python/CreateNothing.py b/docker/test/integration/resources/python/CreateNothing.py index b39dbcee4..acef36dd8 100644 --- a/docker/test/integration/resources/python/CreateNothing.py +++ b/docker/test/integration/resources/python/CreateNothing.py @@ -29,4 +29,5 @@ class CreateNothing(FlowFileSource): pass def create(self, context): + context.yield_resources() return None diff --git a/extensions/python/pythonprocessors/nifiapi/properties.py b/extensions/python/pythonprocessors/nifiapi/properties.py index 20bf34bb3..996a0bece 100644 --- a/extensions/python/pythonprocessors/nifiapi/properties.py +++ b/extensions/python/pythonprocessors/nifiapi/properties.py @@ -308,3 +308,6 @@ class ProcessContext: properties[property_descriptor] = cpp_properties[property_descriptor.name] return properties + + def yield_resources(self): + self.cpp_context.yieldResources() diff --git a/extensions/python/types/PyProcessContext.cpp b/extensions/python/types/PyProcessContext.cpp index 5dd9628ff..cb98bddf0 100644 --- a/extensions/python/types/PyProcessContext.cpp +++ b/extensions/python/types/PyProcessContext.cpp @@ -32,6 +32,7 @@ static PyMethodDef PyProcessContext_methods[] = { // NOLINT(cppcoreguidelines-a {"getControllerService", (PyCFunction) PyProcessContext::getControllerService, METH_VARARGS, nullptr}, {"getName", (PyCFunction) PyProcessContext::getName, METH_VARARGS, nullptr}, {"getProperties", (PyCFunction) PyProcessContext::getProperties, METH_VARARGS, nullptr}, + {"yieldResources", (PyCFunction) PyProcessContext::getProperties, METH_VARARGS, nullptr}, {} /* Sentinel */ }; @@ -168,6 +169,18 @@ PyObject* PyProcessContext::getProperties(PyProcessContext* self, PyObject*) { return object::returnReference(py_properties); } +PyObject* PyProcessContext::yieldResources(PyProcessContext* self, PyObject*) { + auto context = self->process_context_; + if (!context) { + PyErr_SetString(PyExc_AttributeError, "tried reading process context outside 'on_trigger'"); + return nullptr; + } + + context->yield(); + + Py_RETURN_NONE; +} + PyTypeObject* PyProcessContext::typeObject() { static OwnedObject PyProcessContextType{PyType_FromSpec(&PyProcessContextTypeSpec)}; return reinterpret_cast<PyTypeObject*>(PyProcessContextType.get()); diff --git a/extensions/python/types/PyProcessContext.h b/extensions/python/types/PyProcessContext.h index 00c6a04e6..8e3f515b4 100644 --- a/extensions/python/types/PyProcessContext.h +++ b/extensions/python/types/PyProcessContext.h @@ -39,6 +39,7 @@ struct PyProcessContext { static PyObject* getControllerService(PyProcessContext* self, PyObject* args); static PyObject* getName(PyProcessContext* self, PyObject* args); static PyObject* getProperties(PyProcessContext* self, PyObject* args); + static PyObject* yieldResources(PyProcessContext* self, PyObject* args); static PyTypeObject* typeObject(); };
