|
|
@@ -1,4 +1,5 @@
|
|
|
#include "webserver_service.hpp"
|
|
|
+#include <algorithm>
|
|
|
#include "api/auth_controller.hpp"
|
|
|
#include "api/user_controller.hpp"
|
|
|
#include "api/workflow_controller.hpp"
|
|
|
@@ -25,6 +26,26 @@
|
|
|
|
|
|
namespace smartbotic::webserver {
|
|
|
|
|
|
+namespace {
|
|
|
+
|
|
|
+// server.form_dispatch_threads / server.form_dispatch_queue_capacity are read
|
|
|
+// as plain int from JSON config and handed to DispatchConfig fields that are
|
|
|
+// std::size_t: 0 threads means every immediate-mode form submission gets a
|
|
|
+// "thanks, your answer was received" that nothing will ever run, and a
|
|
|
+// negative value silently wraps to an enormous unsigned size on the
|
|
|
+// conversion. Clamp to a sane range and say so, rather than let either
|
|
|
+// mistake pass through as if it were what the operator meant.
|
|
|
+std::size_t clampDispatchSetting(const char* name, int configured, int min_value, int max_value) {
|
|
|
+ int clamped = std::clamp(configured, min_value, max_value);
|
|
|
+ if (clamped != configured) {
|
|
|
+ LOG_WARN("Configured {} of {} is out of the allowed range [{}, {}]; using {} instead",
|
|
|
+ name, configured, min_value, max_value, clamped);
|
|
|
+ }
|
|
|
+ return static_cast<std::size_t>(clamped);
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace
|
|
|
+
|
|
|
WebServerService::WebServerService(const WebServerServiceConfig& config)
|
|
|
: config_(config) {
|
|
|
|
|
|
@@ -417,8 +438,10 @@ void WebServerService::setupRoutes() {
|
|
|
runner_ctrl_->registerRoutes(server);
|
|
|
|
|
|
api::WebhookController::DispatchConfig form_dispatch_config;
|
|
|
- form_dispatch_config.threads = config_.form_dispatch_threads;
|
|
|
- form_dispatch_config.queue_capacity = config_.form_dispatch_queue_capacity;
|
|
|
+ form_dispatch_config.threads =
|
|
|
+ clampDispatchSetting("server.form_dispatch_threads", config_.form_dispatch_threads, 1, 64);
|
|
|
+ form_dispatch_config.queue_capacity = clampDispatchSetting(
|
|
|
+ "server.form_dispatch_queue_capacity", config_.form_dispatch_queue_capacity, 1, 10000);
|
|
|
webhook_ctrl_ = std::make_unique<api::WebhookController>(
|
|
|
*storage_, *runner_registry_, *load_balancer_, *ws_server_, *node_store_, *scheduler_,
|
|
|
*jwt_, form_dispatch_config);
|