martinzink commented on a change in pull request #1228:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1228#discussion_r773805246
##########
File path: extensions/script/ExecuteScript.cpp
##########
@@ -79,80 +79,72 @@ void ExecuteScript::onSchedule(core::ProcessContext
*context, core::ProcessSessi
context->getProperty(ScriptBody.getName(), script_body_);
context->getProperty(ModuleDirectory.getName(), module_directory_);
- if (script_file_.empty() && script_engine_.empty()) {
+ if (script_file_.empty() && script_body_.empty()) {
logger_->log_error("Either Script Body or Script File must be defined");
return;
}
}
void ExecuteScript::onTrigger(const std::shared_ptr<core::ProcessContext>
&context,
const std::shared_ptr<core::ProcessSession>
&session) {
- try {
- std::shared_ptr<script::ScriptEngine> engine;
+ std::shared_ptr<script::ScriptEngine> engine;
- // Use an existing engine, if one is available
- if (script_engine_q_.try_dequeue(engine)) {
- logger_->log_debug("Using available %s script engine instance",
script_engine_);
- } else {
- logger_->log_info("Creating new %s script instance", script_engine_);
- logger_->log_info("Approximately %d %s script instances created for this
processor",
- script_engine_q_.size_approx(),
- script_engine_);
+ // Use an existing engine, if one is available
+ if (script_engine_q_.try_dequeue(engine)) {
+ logger_->log_debug("Using available %s script engine instance",
script_engine_);
+ } else {
+ logger_->log_info("Creating new %s script instance", script_engine_);
+ logger_->log_info("Approximately %d %s script instances created for this
processor",
+ script_engine_q_.size_approx(),
+ script_engine_);
- if (script_engine_ == "python") {
+ if (script_engine_ == "python") {
#ifdef PYTHON_SUPPORT
- engine = createEngine<python::PythonScriptEngine>();
+ engine = createEngine<python::PythonScriptEngine>();
#else
- throw std::runtime_error("Python support is disabled in this build.");
+ throw std::runtime_error("Python support is disabled in this build.");
#endif // PYTHON_SUPPORT
- } else if (script_engine_ == "lua") {
+ } else if (script_engine_ == "lua") {
#ifdef LUA_SUPPORT
- engine = createEngine<lua::LuaScriptEngine>();
+ engine = createEngine<lua::LuaScriptEngine>();
#else
- throw std::runtime_error("Lua support is disabled in this build.");
+ throw std::runtime_error("Lua support is disabled in this build.");
#endif // LUA_SUPPORT
- }
-
- if (engine == nullptr) {
- throw std::runtime_error("No script engine available");
- }
-
- if (!script_body_.empty()) {
- engine->eval(script_body_);
- } else if (!script_file_.empty()) {
- engine->evalFile(script_file_);
- } else {
- throw std::runtime_error("Neither Script Body nor Script File is
available to execute");
- }
}
- if (script_engine_ == "python") {
+ if (engine == nullptr) {
+ throw std::runtime_error("No script engine available");
+ }
+
+ if (!script_body_.empty()) {
+ engine->eval(script_body_);
+ } else if (!script_file_.empty()) {
+ engine->evalFile(script_file_);
+ } else {
+ throw std::runtime_error("Neither Script Body nor Script File is
available to execute");
+ }
+ }
+
+ if (script_engine_ == "python") {
#ifdef PYTHON_SUPPORT
Review comment:
I agree 👍
This is quite old code, and I think it could really use some refactor
(we could replace these template functions and ifdefs with some good old
polymorphism, add allowable values for the ScriptEngine Property etc..)
Originally I didnt wanna inflate this PR with these refactors, how about a
separete PR aiming at refactoring and modernizing the ExecuteScript?
--
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]