lordgamez commented on a change in pull request #1222:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1222#discussion_r763953817
##########
File path: extensions/script/python/ExecutePythonProcessor.cpp
##########
@@ -50,39 +50,72 @@ core::Property
ExecutePythonProcessor::ModuleDirectory(core::PropertyBuilder::cr
->withDefaultValue("")
->build());
-core::Relationship ExecutePythonProcessor::Success("success", "Script
successes");
-core::Relationship ExecutePythonProcessor::Failure("failure", "Script
failures");
+core::Relationship ExecutePythonProcessor::Success("success", "Script
succeeds");
+core::Relationship ExecutePythonProcessor::Failure("failure", "Script fails");
void ExecutePythonProcessor::initialize() {
- setSupportedProperties({
- ScriptFile,
- ScriptBody,
- ModuleDirectory
- });
- setAcceptAllProperties();
- setSupportedRelationships({
- Success,
- Failure
- });
-}
+ if (getProperties().empty()) {
+ setSupportedProperties({
+ ScriptFile,
+ ScriptBody,
+ ModuleDirectory
+ });
+ setAcceptAllProperties();
+ setSupportedRelationships({
+ Success,
+ Failure
+ });
+ }
+
+ if (processor_initialized_) {
+ logger_->log_debug("Processor has already been initialized, returning...");
+ return;
+ }
-void ExecutePythonProcessor::onSchedule(const
std::shared_ptr<core::ProcessContext> &context, const
std::shared_ptr<core::ProcessSessionFactory>& /*sessionFactory*/) {
python_logger_ =
core::logging::LoggerFactory<ExecutePythonProcessor>::getAliasedLogger(getName());
getProperty(ModuleDirectory.getName(), module_directory_);
-
appendPathForImportModules();
- loadScript();
- if (script_to_exec_.empty()) {
- throw std::runtime_error("Neither Script Body nor Script File is available
to execute");
+ try {
+ loadScript();
+ } catch(const std::runtime_error&) {
+ logger_->log_warn("Could not load python script while initializing. In
case of non-native python processor this is normal and will be done in the
schedule phase.");
Review comment:
Normally in the `ExecutePythonProcessor`'s initialize phase the values
of the properties are not yet available like in any other processor. However
when we use a native python processor, after the properties are initialized the
`PythonObjectFactory` sets the `ScriptFile` property's value to the python
processor's file path and calls the `initialize` again and the script will be
loaded.
##########
File path: extensions/script/python/ExecutePythonProcessor.cpp
##########
@@ -50,39 +50,72 @@ core::Property
ExecutePythonProcessor::ModuleDirectory(core::PropertyBuilder::cr
->withDefaultValue("")
->build());
-core::Relationship ExecutePythonProcessor::Success("success", "Script
successes");
-core::Relationship ExecutePythonProcessor::Failure("failure", "Script
failures");
+core::Relationship ExecutePythonProcessor::Success("success", "Script
succeeds");
+core::Relationship ExecutePythonProcessor::Failure("failure", "Script fails");
void ExecutePythonProcessor::initialize() {
- setSupportedProperties({
- ScriptFile,
- ScriptBody,
- ModuleDirectory
- });
- setAcceptAllProperties();
- setSupportedRelationships({
- Success,
- Failure
- });
-}
+ if (getProperties().empty()) {
+ setSupportedProperties({
+ ScriptFile,
+ ScriptBody,
+ ModuleDirectory
+ });
+ setAcceptAllProperties();
+ setSupportedRelationships({
+ Success,
+ Failure
+ });
+ }
+
+ if (processor_initialized_) {
+ logger_->log_debug("Processor has already been initialized, returning...");
+ return;
+ }
-void ExecutePythonProcessor::onSchedule(const
std::shared_ptr<core::ProcessContext> &context, const
std::shared_ptr<core::ProcessSessionFactory>& /*sessionFactory*/) {
python_logger_ =
core::logging::LoggerFactory<ExecutePythonProcessor>::getAliasedLogger(getName());
getProperty(ModuleDirectory.getName(), module_directory_);
-
appendPathForImportModules();
- loadScript();
- if (script_to_exec_.empty()) {
- throw std::runtime_error("Neither Script Body nor Script File is available
to execute");
+ try {
+ loadScript();
+ } catch(const std::runtime_error&) {
+ logger_->log_warn("Could not load python script while initializing. In
case of non-native python processor this is normal and will be done in the
schedule phase.");
Review comment:
Normally in the `ExecutePythonProcessor`'s initialize phase the values
of the properties are not yet available like in any other processor so it will
fail. However when we use a native python processor, after the properties are
initialized the `PythonObjectFactory` sets the `ScriptFile` property's value to
the python processor's file path and calls the `initialize` again and the
script will be loaded.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]