You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/01/05 10:37:32 UTC

[GitHub] [nifi-minifi-cpp] adam-markovics commented on a change in pull request #1232: MINIFICPP-1706 Rework script engine management in ExecuteScript processor

adam-markovics commented on a change in pull request #1232:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1232#discussion_r778713003



##########
File path: extensions/script/ExecuteScript.cpp
##########
@@ -89,40 +113,30 @@ void ExecuteScript::onTrigger(const std::shared_ptr<core::ProcessContext> &conte
                               const std::shared_ptr<core::ProcessSession> &session) {
   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_);
-
-    if (script_engine_ == "python") {
+  if (script_engine_ == "python") {
 #ifdef PYTHON_SUPPORT
-      engine = createEngine<python::PythonScriptEngine>();
+    engine = python_script_engine_;
 #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 = script_engine_q_->getScriptEngine<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 (engine == nullptr) {
+    throw std::runtime_error("No script engine available");
+  }
+
+  if (!script_body_.empty()) {
+    engine->eval(script_body_);
+  } else if (!script_file_.empty()) {

Review comment:
       If we have both script_body_ and script_file_ (erroneously), will we just silently execute script_body_, without telling the user about the misconfiguration?




-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org