Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-2717 [FEAT] Sigterm Implementation in Sidecar Tool container (#1523)

Kirtiman Mishra7f478fb717f0
diff --git a/backend/sample.env b/backend/sample.env
index 1d361d0a8..08658931e 100644
--- a/backend/sample.env
+++ b/backend/sample.env
@@ -89,9 +89,9 @@ PROMPT_STUDIO_FILE_PATH=/app/prompt-studio-data
# Structure Tool Image (Runs prompt studio exported tools)
# https://hub.docker.com/r/unstract/tool-structure
-STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.92"
+STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.94"
STRUCTURE_TOOL_IMAGE_NAME="unstract/tool-structure"
-STRUCTURE_TOOL_IMAGE_TAG="0.0.92"
+STRUCTURE_TOOL_IMAGE_TAG="0.0.94"
# Feature Flags
EVALUATION_SERVER_IP=unstract-flipt
diff --git a/runner/sample.env b/runner/sample.env
index 9a4fd2972..723bc8961 100644
--- a/runner/sample.env
+++ b/runner/sample.env
@@ -52,7 +52,7 @@ FLASK_APP=unstract.runner:app
# Tool Sidecar
TOOL_SIDECAR_ENABLED=False
TOOL_SIDECAR_IMAGE_NAME="unstract/tool-sidecar"
-TOOL_SIDECAR_IMAGE_TAG="0.2.0"
+TOOL_SIDECAR_IMAGE_TAG="0.2.1"
TOOL_EXECUTION_CACHE_TTL_IN_SECOND=86400 # 24 Hours
# File Execution Tracker
diff --git a/tool-sidecar/src/unstract/tool_sidecar/log_processor.py b/tool-sidecar/src/unstract/tool_sidecar/log_processor.py
index 86ade0cd7..7d02954a8 100644
--- a/tool-sidecar/src/unstract/tool_sidecar/log_processor.py
+++ b/tool-sidecar/src/unstract/tool_sidecar/log_processor.py
@@ -7,7 +7,9 @@ completion signals.
import json
import logging
import os
+import signal
import time
+import types
from datetime import UTC, datetime
from typing import Any
@@ -26,6 +28,14 @@ from .dto import LogLineDTO
logger = logging.getLogger(__name__)
+def _signal_handler(signum: int, _frame: types.FrameType | None):
+ """Handle shutdown signals gracefully."""
+ sig = signal.Signals(signum)
+ signal_name = sig.name
+ logger.warning(f"RECEIVED SIGNAL: {signal_name}")
+ logger.warning("Initiating graceful shutdown...")
+
+
class LogProcessor:
def __init__(
self,
@@ -246,6 +256,10 @@ def main():
"""Main entry point for the sidecar container.
Sets up the log processor with environment variables and starts monitoring.
"""
+ # Set up signal handlers for graceful shutdown
+ signal.signal(signal.SIGTERM, _signal_handler)
+ signal.signal(signal.SIGINT, _signal_handler)
+
# Get configuration from environment
log_path = os.getenv(Env.LOG_PATH, "/shared/logs/logs.txt")
redis_host = os.getenv(Env.REDIS_HOST)
diff --git a/tools/classifier/src/config/properties.json b/tools/classifier/src/config/properties.json
index 56dae8929..132343a73 100644
--- a/tools/classifier/src/config/properties.json
+++ b/tools/classifier/src/config/properties.json
@@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "File Classifier",
"functionName": "classify",
- "toolVersion": "0.0.73",
+ "toolVersion": "0.0.74",
"description": "Classifies a file into a bin based on its contents",
"input": {
"description": "File to be classified"
diff --git a/tools/structure/src/config/properties.json b/tools/structure/src/config/properties.json
index 8a09fdb70..6726c9dc3 100644
--- a/tools/structure/src/config/properties.json
+++ b/tools/structure/src/config/properties.json
@@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "Structure Tool",
"functionName": "structure_tool",
- "toolVersion": "0.0.93",
+ "toolVersion": "0.0.94",
"description": "This is a template tool which can answer set of input prompts designed in the Prompt Studio",
"input": {
"description": "File that needs to be indexed and parsed for answers"
diff --git a/tools/text_extractor/src/config/properties.json b/tools/text_extractor/src/config/properties.json
index 9d7d35e12..fd8a767e3 100644
--- a/tools/text_extractor/src/config/properties.json
+++ b/tools/text_extractor/src/config/properties.json
@@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "Text Extractor",
"functionName": "text_extractor",
- "toolVersion": "0.0.69",
+ "toolVersion": "0.0.70",
"description": "The Text Extractor is a powerful tool designed to convert documents to its text form or Extract texts from documents",
"input": {
"description": "Document"
diff --git a/unstract/sdk1/src/unstract/sdk1/tool/entrypoint.py b/unstract/sdk1/src/unstract/sdk1/tool/entrypoint.py
index 831be97d0..a5d183787 100644
--- a/unstract/sdk1/src/unstract/sdk1/tool/entrypoint.py
+++ b/unstract/sdk1/src/unstract/sdk1/tool/entrypoint.py
@@ -1,11 +1,25 @@
+import logging
+import signal
+import types
+
from unstract.sdk1.tool.base import BaseTool
from unstract.sdk1.tool.executor import ToolExecutor
from unstract.sdk1.tool.parser import ToolArgsParser
+logger = logging.getLogger(__name__)
+
class ToolEntrypoint:
"""Class that contains methods for the entrypoint for a tool."""
+ @staticmethod
+ def _signal_handler(signum: int, _frame: types.FrameType | None) -> None:
+ """Handle SIGTERM and SIGINT signals."""
+ sig = signal.Signals(signum)
+ signal_name = sig.name
+ logger.warning(f"RECEIVED SIGNAL: {signal_name}")
+ logger.warning("Initiating graceful shutdown...")
+
@staticmethod
def launch(tool: BaseTool, args: list[str]) -> None:
"""Entrypoint function for a tool.
@@ -17,6 +31,10 @@ class ToolEntrypoint:
tool (AbstractTool): Tool to execute
args (List[str]): Arguments passed to a tool
"""
+ # Register signal handlers for graceful shutdown
+ signal.signal(signal.SIGTERM, ToolEntrypoint._signal_handler)
+ signal.signal(signal.SIGINT, ToolEntrypoint._signal_handler)
+
parsed_args = ToolArgsParser.parse_args(args)
executor = ToolExecutor(tool=tool)
executor.execute(parsed_args)
diff --git a/unstract/tool-registry/tool_registry_config/public_tools.json b/unstract/tool-registry/tool_registry_config/public_tools.json
index 0d1a767f3..b9b4d9b97 100644
--- a/unstract/tool-registry/tool_registry_config/public_tools.json
+++ b/unstract/tool-registry/tool_registry_config/public_tools.json
@@ -5,7 +5,7 @@
"schemaVersion": "0.0.1",
"displayName": "File Classifier",
"functionName": "classify",
- "toolVersion": "0.0.73",
+ "toolVersion": "0.0.74",
"description": "Classifies a file into a bin based on its contents",
"input": {
"description": "File to be classified"
@@ -106,9 +106,9 @@
"properties": {}
},
"icon": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg\n enable-background=\"new 0 0 20 20\"\n height=\"48\"\n viewBox=\"0 0 20 20\"\n width=\"48\"\n fill=\"#000000\"\n version=\"1.1\"\n id=\"svg8109\"\n sodipodi:docname=\"folder_copy_black_48dp.svg\"\n xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:svg=\"http://www.w3.org/2000/svg\">\n <defs\n id=\"defs8113\" />\n <sodipodi:namedview\n id=\"namedview8111\"\n pagecolor=\"#ffffff\"\n bordercolor=\"#000000\"\n borderopacity=\"0.25\"\n inkscape:showpageshadow=\"2\"\n inkscape:pageopacity=\"0.0\"\n inkscape:pagecheckerboard=\"0\"\n inkscape:deskcolor=\"#d1d1d1\"\n showgrid=\"false\" />\n <g\n id=\"g8099\">\n <rect\n fill=\"none\"\n height=\"20\"\n width=\"20\"\n x=\"0\"\n id=\"rect8097\"\n y=\"0\" />\n </g>\n <g\n id=\"g8107\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <g\n id=\"g8105\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <path\n d=\"M 2.5,5 H 1 V 15.5 C 1,16.33 1.67,17 2.5,17 H 15.68 V 15.5 H 2.5 Z\"\n id=\"path8101\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n <path\n d=\"M 16.5,4 H 11 L 9,2 H 5.5 C 4.67,2 4,2.67 4,3.5 v 9 C 4,13.33 4.67,14 5.5,14 h 11 c 0.83,0 1.5,-0.67 1.5,-1.5 v -7 C 18,4.67 17.33,4 16.5,4 Z m 0,8.5 h -11 v -9 h 2.88 l 2,2 h 6.12 z\"\n id=\"path8103\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n </g>\n </g>\n</svg>\n",
- "image_url": "docker:unstract/tool-classifier:0.0.73",
+ "image_url": "docker:unstract/tool-classifier:0.0.74",
"image_name": "unstract/tool-classifier",
- "image_tag": "0.0.73"
+ "image_tag": "0.0.74"
},
"text_extractor": {
"tool_uid": "text_extractor",
@@ -116,7 +116,7 @@
"schemaVersion": "0.0.1",
"displayName": "Text Extractor",
"functionName": "text_extractor",
- "toolVersion": "0.0.69",
+ "toolVersion": "0.0.70",
"description": "The Text Extractor is a powerful tool designed to convert documents to its text form or Extract texts from documents",
"input": {
"description": "Document"
@@ -191,8 +191,8 @@
}
},
"icon": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg\n enable-background=\"new 0 0 20 20\"\n height=\"48\"\n viewBox=\"0 0 20 20\"\n width=\"48\"\n fill=\"#000000\"\n version=\"1.1\"\n id=\"svg8109\"\n sodipodi:docname=\"folder_copy_black_48dp.svg\"\n xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:svg=\"http://www.w3.org/2000/svg\">\n <defs\n id=\"defs8113\" />\n <sodipodi:namedview\n id=\"namedview8111\"\n pagecolor=\"#ffffff\"\n bordercolor=\"#000000\"\n borderopacity=\"0.25\"\n inkscape:showpageshadow=\"2\"\n inkscape:pageopacity=\"0.0\"\n inkscape:pagecheckerboard=\"0\"\n inkscape:deskcolor=\"#d1d1d1\"\n showgrid=\"false\" />\n <g\n id=\"g8099\">\n <rect\n fill=\"none\"\n height=\"20\"\n width=\"20\"\n x=\"0\"\n id=\"rect8097\"\n y=\"0\" />\n </g>\n <g\n id=\"g8107\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <g\n id=\"g8105\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <path\n d=\"M 2.5,5 H 1 V 15.5 C 1,16.33 1.67,17 2.5,17 H 15.68 V 15.5 H 2.5 Z\"\n id=\"path8101\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n <path\n d=\"M 16.5,4 H 11 L 9,2 H 5.5 C 4.67,2 4,2.67 4,3.5 v 9 C 4,13.33 4.67,14 5.5,14 h 11 c 0.83,0 1.5,-0.67 1.5,-1.5 v -7 C 18,4.67 17.33,4 16.5,4 Z m 0,8.5 h -11 v -9 h 2.88 l 2,2 h 6.12 z\"\n id=\"path8103\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n </g>\n </g>\n</svg>\n",
- "image_url": "docker:unstract/tool-text-extractor:0.0.69",
+ "image_url": "docker:unstract/tool-text-extractor:0.0.70",
"image_name": "unstract/tool-text-extractor",
- "image_tag": "0.0.69"
+ "image_tag": "0.0.70"
}
}