Skip to content

Commit

Permalink
MINIFICPP-2453 Add yield function support to python API
Browse files Browse the repository at this point in the history
Closes #1865

Signed-off-by: Marton Szasz <[email protected]>
  • Loading branch information
lordgamez authored and szaszm committed Sep 26, 2024
1 parent 1eccfd8 commit 66e465d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/test/integration/resources/python/CreateNothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ def __init__(self, **kwargs):
pass

def create(self, context):
context.yield_resources()
return None
3 changes: 3 additions & 0 deletions extensions/python/pythonprocessors/nifiapi/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,6 @@ def getProperties(self) -> Dict[PropertyDescriptor, str]:
properties[property_descriptor] = cpp_properties[property_descriptor.name]

return properties

def yield_resources(self):
self.cpp_context.yieldResources()
13 changes: 13 additions & 0 deletions extensions/python/types/PyProcessContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};

Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions extensions/python/types/PyProcessContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down

0 comments on commit 66e465d

Please sign in to comment.