Successfully extracted magic numbers and strings to ObjConstants.py and
added comprehensive type hints to WebHooks.py.
Added a new WebHookConstants class containing 50+ constants for webhook
operations:
Queue and Pool Configuration:
POOL_SIZE = 100QUEUE_SIZE = 10000MAGIC_TOKEN = "ba1f1d83-7a88-4ca6-b0d7-84876e5b5dca"HTTP Status Codes:
HTTP_OK = 200HTTP_BAD_REQUEST = 400HTTP_UNAUTHORIZED = 401HTTP_NOT_FOUND = 404HTTP_SERVER_ERROR = 500Plus string versions for legacy support (HTTP_OK_STR, etc.)
Webhook Status Values:
STATUS_ERROR = "Error"STATUS_SUCCESS = "Success"Parameter Value Types:
VALUE_TYPE_INT = "INT"VALUE_TYPE_FLOAT = "FLOAT"VALUE_TYPE_JSON = "JSON"VALUE_TYPE_STRING = "STRING"VALUE_TYPE_TEXT = "TEXT"VALUE_TYPE_DOCUMENT = "DOCUMENT"VALUE_TYPE_DISPLAY = "DISPLAY"VALUE_TYPE_NOTE = "NOTE"Post Types:
POST_TYPE_POST = "POST"POST_TYPE_HEAD = "HEAD"POST_TYPE_GET = "GET"POST_TYPE_RETURN = "RETURN"POST_TYPE_DERIVED = "DERIVED"POST_TYPE_ENCODED = "ENCODED"POST_TYPE_PATCH = "PATCH"POST_TYPE_LOOKUP = "LOOKUP"POST_TYPE_JSON = "JSON"Webhook Direction:
DIRECTION_IN = "IN"DIRECTION_OUT = "OUT"Package Defaults:
PACKAGE_CORE = "CORE"PACKAGE_ADHOC = "ADHOC"PACKAGE_BASE = "base"Active Flags:
ACTIVE_YES = "Y"ACTIVE_NO = "N"Payload Types:
PAYLOAD_TYPE_XML = "XML"PAYLOAD_TYPE_JSON = "JSON"Table Names:
TABLE_DEF_WEBHOOK = "def_webhook"TABLE_DEF_WEBHOOK_PARAMETERS = "def_webhook_parameters"TABLE_DEF_WEBHOOK_VALIDATIONS = "def_webhook_validations"TABLE_DEF_WEBHOOK_OUTPUT_VALIDATIONS = "def_webhook_output_validations"TABLE_DEF_WEBHOOK_REFLECTIONS = "def_webhook_reflections"TABLE_DEF_WEBHOOK_BATCH = "def_webhook_batch"TABLE_SYS_USER = "sys_User"Validation Messages:
MSG_REQUIRED_MISSING = "Required output fields missing"MSG_TYPE_VALIDATION_FAILED = "Output type validation failed"MSG_CUSTOM_VALIDATION_FAILED = "Custom validation failed"Limits and Timeouts:
MAX_BATCH_SIZE = 10000MIN_BATCH_SIZE = 1DEFAULT_VALIDATION_TIMEOUT = 30DEFAULT_WORKFLOW_TIMEOUT = 300Module-level constants updated:
# Before:
POOL_SIZE = 100
QUEUE_SIZE = 10000
MAGIC_TOKEN = "ba1f1d83-7a88-4ca6-b0d7-84876e5b5dca"
# After:
from ObjConstants import WebHookConstants
POOL_SIZE = WebHookConstants.POOL_SIZE
QUEUE_SIZE = WebHookConstants.QUEUE_SIZE
MAGIC_TOKEN = WebHookConstants.MAGIC_TOKEN
HTTP status codes updated:
# Before:
self.success_value = "200"
if self.results["Statuscode"] == 400:
# After:
self.success_value = WebHookConstants.HTTP_OK_STR
if self.results["Statuscode"] == WebHookConstants.HTTP_BAD_REQUEST:
Validation constants updated:
# Before:
self.success = "Error"
self.success_value = 400
# After:
self.success = WebHookConstants.STATUS_ERROR
self.success_value = WebHookConstants.HTTP_BAD_REQUEST
Value type constants updated:
# Before:
if expected_type.upper() == "INT":
elif expected_type.upper() == "FLOAT":
elif expected_type.upper() == "JSON":
# After:
if expected_type.upper() == WebHookConstants.VALUE_TYPE_INT:
elif expected_type.upper() == WebHookConstants.VALUE_TYPE_FLOAT:
elif expected_type.upper() == WebHookConstants.VALUE_TYPE_JSON:
Added typing imports:
from typing import Dict, List, Tuple, Optional, Any, Union
WebHooks.init with type hints:
def __init__(
self,
DB: Optional[Any] = 0,
base_table: str = ""
) -> None:
self.params: Dict[str, Any] = dict()
self.returns: Dict[str, Any] = dict()
self.required: Dict[str, str] = dict()
# ... etc
RenderResult with type hints and docstring:
def RenderResult(
self,
noreturn: int = 0
) -> Tuple[Union[Dict[str, Any], str], int]:
"""
Render final webhook result with validation.
Args:
noreturn: Flag to skip result rendering (0=normal, 1=skip)
Returns:
Tuple of (results_dict, status_code) or ("", status_code)
"""
set_parameter with type hints and docstring:
def set_parameter(self, Param: str, Value: Any) -> None:
"""
Set a webhook parameter value.
Args:
Param: Parameter name (NormalParameter)
Value: Parameter value to set
"""
hook_concurrent function with type hints and docstring:
def hook_concurrent(
counter: int,
webhook: str,
list_set: List[str],
batch_set: Dict[str, Any]
) -> None:
"""
Process webhook for a subset of GUIDs concurrently.
Args:
counter: Thread counter for tracking
webhook: Webhook code to process
list_set: List of GUIDs to process
batch_set: Dictionary of GUID -> data mappings
"""
WebHooksSet class methods with type hints:
class WebHooksSet(ObjData.ObjData):
"""Batch processing for webhooks."""
def Reset(self) -> None:
"""Reset webhook set state."""
def ProcessSet(
self,
webhook: str,
batch: Dict[str, Any]
) -> None:
"""
Process a batch of webhooks using thread pool.
Args:
webhook: Webhook code to process
batch: Dictionary of GUID -> data mappings
"""
def ReadSet(self, webhook: str) -> None:
"""
Read and process a batch set of webhook records.
Args:
webhook: Webhook code to process in batch mode
"""
def Transform(self) -> None:
"""Transform all items in the webhook set."""
if self.results["Statuscode"] == 400:
self.success = "Error"
self.success_value = 400
if self.results["Statuscode"] == WebHookConstants.HTTP_BAD_REQUEST:
self.success = WebHookConstants.STATUS_ERROR
self.success_value = WebHookConstants.HTTP_BAD_REQUEST
def RenderResult(self, noreturn=0):
# What type is noreturn? What does it return?
def RenderResult(
self,
noreturn: int = 0
) -> Tuple[Union[Dict[str, Any], str], int]:
"""
Render final webhook result with validation.
Args:
noreturn: Flag to skip result rendering (0=normal, 1=skip)
Returns:
Tuple of (results_dict, status_code) or ("", status_code)
"""
factory.core/ObjConstants.py
WebHookConstants class (50+ constants)__all__ export listfrom typing import ... importsfrom ObjConstants import WebHookConstantsmypy factory.web/WebHooks.py
# Search for any remaining magic numbers
ruff check factory.web/WebHooks.py
pytest resource.test/pytests/factory.web/ -v
from ObjConstants import WebHookConstants
# Verify all constants accessible
assert WebHookConstants.HTTP_OK == 200
assert WebHookConstants.HTTP_BAD_REQUEST == 400
assert WebHookConstants.STATUS_ERROR == "Error"
# In ObjConstants.py or types.py
WebhookParams = Dict[str, Any]
ValidationList = List[Tuple[str, str]]
from enum import IntEnum
class HttpStatus(IntEnum):
OK = 200
BAD_REQUEST = 400
UNAUTHORIZED = 401
from dataclasses import dataclass
@dataclass
class WebhookResult:
results: Dict[str, Any]
status_code: int
success_note: str
CLAUDE.md - Project coding standardsObjConstants.py - Constant definitionsSQL_TO_YAML_PROGRESS.md - SQL migration progressWEBHOOKS_SQL_REFACTORING.md - SQL refactoring guideUpdated: 2026-02-19