mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
test: Add integration tests for execution flows in native Python runner (#19198)
This commit is contained in:
@@ -62,7 +62,7 @@ ENV_ENVIRONMENT = "ENVIRONMENT"
|
||||
ENV_DEPLOYMENT_NAME = "DEPLOYMENT_NAME"
|
||||
|
||||
# Sentry
|
||||
SENTRY_TAG_SERVER_TYPE = "server_type"
|
||||
SENTRY_TAG_SERVER_TYPE_KEY = "server_type"
|
||||
SENTRY_TAG_SERVER_TYPE_VALUE = "task_runner_python"
|
||||
|
||||
# Logging
|
||||
|
||||
@@ -6,7 +6,7 @@ from src.config.sentry_config import SentryConfig
|
||||
from src.constants import (
|
||||
EXECUTOR_FILENAMES,
|
||||
LOG_SENTRY_MISSING,
|
||||
SENTRY_TAG_SERVER_TYPE,
|
||||
SENTRY_TAG_SERVER_TYPE_KEY,
|
||||
SENTRY_TAG_SERVER_TYPE_VALUE,
|
||||
)
|
||||
|
||||
@@ -25,14 +25,14 @@ class TaskRunnerSentry:
|
||||
release=f"n8n@{self.config.n8n_version}",
|
||||
environment=self.config.environment,
|
||||
server_name=self.config.deployment_name,
|
||||
before_send=self._filter_out_user_code_errors,
|
||||
before_send=self._filter_out_ignored_errors,
|
||||
attach_stacktrace=True,
|
||||
send_default_pii=False,
|
||||
auto_enabling_integrations=False,
|
||||
default_integrations=True,
|
||||
integrations=[LoggingIntegration(level=logging.ERROR)],
|
||||
)
|
||||
sentry_sdk.set_tag(SENTRY_TAG_SERVER_TYPE, SENTRY_TAG_SERVER_TYPE_VALUE)
|
||||
sentry_sdk.set_tag(SENTRY_TAG_SERVER_TYPE_KEY, SENTRY_TAG_SERVER_TYPE_VALUE)
|
||||
self.logger.info("Sentry ready")
|
||||
|
||||
def shutdown(self) -> None:
|
||||
@@ -41,7 +41,7 @@ class TaskRunnerSentry:
|
||||
sentry_sdk.flush(timeout=2.0)
|
||||
self.logger.info("Sentry stopped")
|
||||
|
||||
def _filter_out_user_code_errors(self, event: Any, hint: Any) -> Optional[Any]:
|
||||
def _filter_out_ignored_errors(self, event: Any, hint: Any) -> Optional[Any]:
|
||||
if "exc_info" in hint:
|
||||
exc_type, _, _ = hint["exc_info"]
|
||||
if exc_type is TaskRuntimeError:
|
||||
|
||||
@@ -97,6 +97,10 @@ class TaskRunner:
|
||||
f"ws://{websocket_host}{TASK_BROKER_WS_PATH}?id={self.runner_id}"
|
||||
)
|
||||
|
||||
@property
|
||||
def running_tasks_count(self) -> int:
|
||||
return len(self.running_tasks)
|
||||
|
||||
async def start(self) -> None:
|
||||
if self.config.is_auto_shutdown_enabled and not self.on_idle_timeout:
|
||||
raise NoIdleTimeoutHandlerError(self.config.auto_shutdown_timeout)
|
||||
@@ -155,7 +159,7 @@ class TaskRunner:
|
||||
|
||||
timeout = self.config.graceful_shutdown_timeout
|
||||
self.logger.debug(
|
||||
f"Waiting for {len(self.running_tasks)} tasks to complete (timeout: {timeout}s)..."
|
||||
f"Waiting for {self.running_tasks_count} tasks to complete (timeout: {timeout}s)..."
|
||||
)
|
||||
|
||||
start_time = time.time()
|
||||
@@ -164,14 +168,14 @@ class TaskRunner:
|
||||
|
||||
if self.running_tasks:
|
||||
self.logger.warning(
|
||||
f"Timed out waiting for {len(self.running_tasks)} tasks to complete"
|
||||
f"Timed out waiting for {self.running_tasks_count} tasks to complete"
|
||||
)
|
||||
|
||||
async def _terminate_tasks(self):
|
||||
if not self.running_tasks:
|
||||
return
|
||||
|
||||
self.logger.warning(f"Terminating {len(self.running_tasks)} tasks...")
|
||||
self.logger.warning(f"Terminating {self.running_tasks_count} tasks...")
|
||||
|
||||
tasks_to_terminate = [
|
||||
asyncio.to_thread(self.executor.stop_process, task_state.process)
|
||||
@@ -237,7 +241,7 @@ class TaskRunner:
|
||||
await self._send_message(response)
|
||||
return
|
||||
|
||||
if len(self.running_tasks) >= self.config.max_concurrency:
|
||||
if self.running_tasks_count >= self.config.max_concurrency:
|
||||
response = RunnerTaskRejected(
|
||||
task_id=message.task_id,
|
||||
reason=TASK_REJECTED_REASON_AT_CAPACITY,
|
||||
@@ -403,7 +407,7 @@ class TaskRunner:
|
||||
self.open_offers.pop(offer_id, None)
|
||||
|
||||
offers_to_send = self.config.max_concurrency - (
|
||||
len(self.open_offers) + len(self.running_tasks)
|
||||
len(self.open_offers) + self.running_tasks_count
|
||||
)
|
||||
|
||||
for _ in range(offers_to_send):
|
||||
@@ -442,7 +446,7 @@ class TaskRunner:
|
||||
try:
|
||||
await asyncio.sleep(self.config.auto_shutdown_timeout)
|
||||
|
||||
if len(self.running_tasks) > 0:
|
||||
if self.running_tasks_count > 0:
|
||||
return
|
||||
|
||||
assert self.on_idle_timeout is not None # validated at start()
|
||||
|
||||
Reference in New Issue
Block a user