mirror of https://github.com/apache/nifi.git
NIFI-13660 ProcessContext.yieldResources() can be called from Python code
Closes #9182 Signed-off-by: Marton Szasz <szaszm@apache.org>
This commit is contained in:
parent
0510e716b4
commit
5f0cbed5a6
|
@ -324,8 +324,10 @@ created in the Processor's Python code. `attributes` and `contents` are both opt
|
|||
the FlowFile will still have the usual `filename`, `path` and `uuid` attributes, but no additional ones.
|
||||
If `contents` is not provided, a FlowFile with no contents (only attributes) will be created.
|
||||
In case there is no useful information to return from the `create` method, `return None` can be used instead of returning an
|
||||
empty `FlowFileSourceResult`. When `create` returns with `None`, the processor does not produce any output.
|
||||
|
||||
empty `FlowFileSourceResult`. When `create()` returns with `None`, the processor does not produce any output.
|
||||
When there is nothing to return, it might be useful to yield the processor's resources and not schedule the processor
|
||||
to run for the period of time defined by the processor's Yield Duration. This can be achieved by calling
|
||||
`context.yield_resources()` from the processor's `create` method right before returning `None`.
|
||||
|
||||
|
||||
[[property-descriptors]]
|
||||
|
|
|
@ -346,6 +346,9 @@ class ProcessContext(PropertyContext):
|
|||
def getName(self):
|
||||
return self.name
|
||||
|
||||
def yield_resources(self):
|
||||
JvmHolder.java_gateway.get_method(self.java_context, "yield")()
|
||||
|
||||
|
||||
class ValidationContext(PropertyContext):
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import logging
|
|||
import os
|
||||
import sys
|
||||
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
|
||||
from py4j import java_gateway
|
||||
from py4j.java_gateway import JavaGateway, CallbackServerParameters, GatewayParameters
|
||||
|
||||
import ExtensionManager
|
||||
|
@ -122,6 +123,7 @@ if __name__ == "__main__":
|
|||
from nifiapi.__jvm__ import JvmHolder
|
||||
JvmHolder.jvm = gateway.jvm
|
||||
JvmHolder.gateway = gateway
|
||||
JvmHolder.java_gateway = java_gateway
|
||||
|
||||
# We need to import PythonProcessorAdapter but cannot import it at the top of the class because we must first initialize the Gateway,
|
||||
# since there are statically defined objects in the file that contains PythonProcessorAdapter, and those statically defined objects require the Gateway.
|
||||
|
|
Loading…
Reference in New Issue