惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
C
Cisco Blogs
The Hacker News
The Hacker News
T
Threatpost
S
Schneier on Security
K
Kaspersky official blog
Spread Privacy
Spread Privacy
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
NISL@THU
NISL@THU
量子位
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News and Events Feed by Topic
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
V
V2EX
Webroot Blog
Webroot Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
Simon Willison's Weblog
Simon Willison's Weblog
L
LangChain Blog
W
WeLiveSecurity
Cloudbric
Cloudbric

博客园 - ®Geovin Du Dream Park™

go: Functional Options Pattern go:Timing Functions Pattern python: Timing Functions Pattern go: Steady-State Pattern python: Steady-State Pattern go: Handshaking Pattern python: Handshaking Pattern go: Fail-Fast Pattern python: Fail-Fast Pattern I go: Deadline Pattern go: Circuit-Breaker Pattern python: Circuit-Breaker Pattern go: Bulkheads Pattern python: Bulkheads Pattern go: Push & Pull Pattern python: Push & Pull Pattern python: Publish/Subscribe Pattern II go: Publish/Subscribe Pattern python: Publish/Subscribe Pattern go: Futures & Promises Pattern python: Futures & Promises Pattern go: Worker Pool Pattern go:Pipeline Pattern python: Worker Pool Pattern python: Pipeline Pattern go: Fan-Out Pattern python: Fan-Out Pattern go: Fan-In Pattern python: Fan-In Pattern Fan-In go: Producer Consumer  Pattern python: Producer Consumer Pattern go: Parallelism Pattern python: Parallelism Pattern go: Reactor Pattern python: Reactor Pattern go: Generators Pattern python: speech to text offline python: Generators Pattern go: Coroutines Pattern python:Coroutines Pattern go: Broadcast Pattern python: Broadcast Pattern python: Bounded Parallelism Pattern go: Bounded Parallelism Pattern python: N-Barrier Pattern go: N-Barrier Pattern python: Semaphore Pattern go: Semaphore Pattern python: Read-Write Lock Pattern go: Read-Write Lock Pattern python: Monitor Pattern go: Monitor Pattern python: Mutex Pattern go: Lock/Mutex Pattern Python: Condition Variable Pattern go:Condition Variable Pattern python: Registry Pattern python: Interpreter Pattern go: Interpreter Pattern go: Registry Pattern go: Memento Pattern go: Command Pattern go: State Pattern go:Template Method Pattern go: Strategy Pattern go: Visitor Pattern go: Observer Pattern go: Mediator Pattern go: Iterator Pattern go: Chain of Responsibility Pattern go: Proxy Pattern go:Decorator Pattern go: Facade Pattern go: Flyweight Pattern go: Composite Pattern go: Singleton Pattern go: Prototype Pattern go: Bridge Pattern go: Adapter Pattern go: Builder Pattern 密码进行加盐哈希 using CSharp,Python,Go,Java go: Abstract Factory Pattern go: Model,Interface,DAL ,Factory,BLL using mysql go: Simple Factory Pattern go: Factory Method Pattern go: goLang 在Windows环境搭建Go语言开发环境 CSharp: Parallel Extensions cpp: class python: 蝴蝶跟随鼠标 javascript: 中国历史人物热力分布图using echart javascript: 中国历史人物热力图 python: 初养龙虾微信纯文字自动回复using workBuddy python: object 入门 python: Factory Method Pattern python: Simple Factory Pattern python: Abstract Factory Pattern 区域化 代码 python: Null Object Pattern python: Builder Pattern python: Adapter Pattern
python: Deadline Pattern
®Geovin Du Dream Park™ · 2026-06-29 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 20:09 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : exceptions.py



class BusinessException(Exception):
    """
    业务基础异常
    """
    pass

class ServiceTimeoutException(BusinessException):
    """
    服务超时异常(截止日期模式触发)
    """
    pass

class ServiceInvokeException(BusinessException):
    """
    服务调用失败异常
    """
    pass


# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 20:10 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : logger.py
import logging
import sys

def get_logger(name: str) -> logging.Logger:
    """
    企业日志
    :param name:
    :return:
    """
    logger = logging.getLogger(name)
    logger.setLevel(logging.INFO)

    formatter = logging.Formatter(
        "%(asctime)s | %(levelname)s | %(name)s | %(message)s"
    )

    console_handler = logging.StreamHandler(sys.stdout)
    console_handler.setFormatter(formatter)
    logger.addHandler(console_handler)

    logger.propagate = False
    return logger



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 20:10 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : deadline.py
import threading
from typing import Callable, Any, Generic, TypeVar
from DeadlinePattern.common.exceptions import ServiceTimeoutException, ServiceInvokeException
from DeadlinePattern.common.logger import get_logger

logger = get_logger("DeadlinePattern")
T = TypeVar("T")

class DeadlineExecutor(Generic[T]):
    """
    截止日期模式(企业级核心)
    企业级截止日期模式执行器
    职责:统一处理超时任务,超时终止等待,保证系统稳定性
    """
    def __init__(self, timeout_seconds: float):
        self.timeout = timeout_seconds
        self.result: T | None = None
        self.error: Exception | None = None

    def _run(self, func: Callable[[], T]):
        try:
            self.result = func()
        except Exception as e:
            self.error = e

    def execute(self, func: Callable[[], T]) -> T:
        thread = threading.Thread(target=self._run, args=(func,))
        thread.start()
        thread.join(self.timeout)

        if thread.is_alive():
            logger.error(f"任务超时,已终止等待,超时={self.timeout}s")
            raise ServiceTimeoutException("超时:响应概率极低,主动终止等待")

        if self.error:
            raise ServiceInvokeException(f"服务执行异常:{str(self.error)}")

        logger.info("任务执行完成")
        return self.result


# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 20:08 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : config.py
# 全局超时配置(截止日期模式超时时间)
GEM_IDENTIFY_TIMEOUT_SECONDS = 3

# 业务配置
ORDER_ID_PREFIX = "JEWELRY_ORDER"



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 20:13 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : models.py
from dataclasses import dataclass
from typing import Optional

@dataclass
class GemIdentifyResult:
    """
    宝石鉴定结果实体
    """
    gem_type: str
    carat: float
    color: str
    clarity: str
    identify_no: str

@dataclass
class JewelryOrder:
    """
    珠宝订单实体
    """
    order_id: str
    identify_result: Optional[GemIdentifyResult] = None
    material_approved: bool = False
    produce_finished: bool = False
    quality_passed: bool = False
    delivered: bool = False
# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 21:00 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : gem_identify_service.py
import random
import time
from DeadlinePattern.domain.models import GemIdentifyResult
from DeadlinePattern.common.logger import get_logger

logger = get_logger("GemIdentifyService")

class GemIdentifyService:
    """
     第三方宝石鉴定服务(外部不稳定依赖)
    """
    def identify(self) -> GemIdentifyResult:
        """

        :return:
        """

        logger.info("开始调用第三方宝石鉴定服务...")
        # 随机控制响应速度:50%快速,50%超长耗时触发截止期限
        if random.random() > 0.5:
            delay = 1
        else:
            delay = 10
        time.sleep(delay)

        res = GemIdentifyResult(
            gem_type="钻石",
            carat=1.0,
            color="D",
            clarity="VVS1",
            identify_no=f"GEM_{random.randint(100000,999999)}"
        )
        logger.info(f"鉴定完成:{res}")
        return res
'''
class GemIdentifyService:
    """
    第三方宝石鉴定服务(外部不稳定依赖)
    """

    def identify(self) -> GemIdentifyResult:
        """

        :return:
        """
        logger.info("开始调用第三方宝石鉴定服务...")
        # 模拟不稳定:50% 1秒返回,50% 10秒返回
        delay = 1 if random.random() > 0.5 else 10
        time.sleep(delay)

        result = GemIdentifyResult(
            gem_type="钻石",
            carat=1.0,
            color="D",
            clarity="VVS1",
            identify_no=f"GEM_{random.randint(100000, 999999)}"
        )

        logger.info(f"鉴定完成:{result}")
        return result
'''


# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 21:02 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : material_service.py
from DeadlinePattern.common.logger import get_logger
logger = get_logger("MaterialService")

class MaterialService:
    """

    """
    def approve(self) -> bool:
        logger.info("原料采购审核中...")
        return True



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 21:03 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : produce_service.py
from DeadlinePattern.common.logger import get_logger
logger = get_logger("ProduceService")

class ProduceService:
    """

    """
    def produce(self) -> bool:
        """

        :return:
        """
        logger.info("工厂加工生产完成")
        return True


# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 21:04 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : quality_service.py
from DeadlinePattern.common.logger import get_logger

logger = get_logger("QualityService")

class QualityService:
    """

    """
    def check(self) -> bool:
        """

        :return:
        """

        logger.info("成品质检合格")
        return True


# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 21:05 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : deliver_service.py
from DeadlinePattern.common.logger import get_logger

logger = get_logger("DeliverService")

class DeliverService:
    """

    """
    def deliver(self) -> bool:
        """

        :return:
        """
        logger.info("订单已交付")
        return True



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Deadline Pattern 截止期限模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 20:08 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : workflow_manager.py
from DeadlinePattern.domain.models import JewelryOrder, GemIdentifyResult
from DeadlinePattern.service.external.gem_identify_service import GemIdentifyService
from DeadlinePattern.service.internal.material_service import MaterialService
from DeadlinePattern.service.internal.produce_service import ProduceService
from DeadlinePattern.service.internal.quality_service import QualityService
from DeadlinePattern.service.internal.deliver_service import DeliverService
from DeadlinePattern.common.deadline import DeadlineExecutor
from DeadlinePattern.common.exceptions import ServiceTimeoutException
from DeadlinePattern.common.logger import get_logger
from DeadlinePattern.config.config import GEM_IDENTIFY_TIMEOUT_SECONDS

logger = get_logger("WorkflowManager")


class JewelryWorkflowManager:
    """
     流程编排器(核心)
    珠宝全流程管理器
    职责:统一编排所有服务,不实现业务逻辑
    """
    
    def __init__(self):
        self.identify = GemIdentifyService()
        self.material = MaterialService()
        self.produce = ProduceService()
        self.quality = QualityService()
        self.deliver = DeliverService()

    # 
    def run(self, order: JewelryOrder):
        """
        
        :param order: 
        :return: 
        """
        logger.info(f"开始执行订单全流程:{order.order_id}")
        try:
            exec = DeadlineExecutor[GemIdentifyResult](GEM_IDENTIFY_TIMEOUT_SECONDS)
            order.identify_result = exec.execute(self.identify.identify)
        except ServiceTimeoutException:
            logger.error("鉴定超时,启动人工复核兜底流程")

        order.material_approved = self.material.approve()
        order.produce_finished = self.produce.produce()
        order.quality_passed = self.quality.check()
        order.delivered = self.deliver.deliver()

        logger.info(f"订单全流程执行完成:{order.order_id}")
        return order

'''
class JewelryWorkflowManager:
    """
    流程编排器(核心)
    珠宝全流程管理器
    职责:统一编排所有服务,不实现业务逻辑
    """
    def __init__(self):
        # 依赖注入(可扩展、可测试)
        self.identify_service = GemIdentifyService()
        self.material_service = MaterialService()
        self.produce_service = ProduceService()
        self.quality_service = QualityService()
        self.deliver_service = DeliverService()

    def execute_full_workflow(self, order: JewelryOrder) -> JewelryOrder:
        """

        :param order:
        :return:
        """

        logger.info(f"开始执行订单全流程:{order.order_id}")

        # ===================== 截止日期模式:鉴定服务 =====================
        try:
            executor = DeadlineExecutor[GemIdentifyResult](GEM_IDENTIFY_TIMEOUT_SECONDS)
            identify_result = executor.execute(self.identify_service.identify)
            order.identify_result = identify_result

        except ServiceTimeoutException:
            logger.error("鉴定超时,启动人工复核兜底流程")
            # 企业级兜底逻辑,不阻塞主流程

        # ===================== 内部稳定流程 =====================
        order.material_approved = self.material_service.approve()
        order.produce_finished = self.produce_service.produce()
        order.quality_passed = self.quality_service.check()
        order.delivered = self.deliver_service.deliver()

        logger.info(f"订单全流程执行完成:{order.order_id}")
        return order
'''

调用:

# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/29 21:07 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : DeadlineBll.py
import time
import random
from DeadlinePattern.domain.models import JewelryOrder
from DeadlinePattern.core.workflow_manager import JewelryWorkflowManager
from DeadlinePattern.common.logger import get_logger
from DeadlinePattern.config.config import ORDER_ID_PREFIX

logger = get_logger("DeadlineBll")

class DeadlineBll(object):
    """

    """
    def demo(self):
        """

        :return:
        """
        print("===== 展示【Deadline Pattern(截止期限模式)】示例 =====")

        logger.info("=== 珠宝定制系统启动 ===")
        order = JewelryOrder(f"{ORDER_ID_PREFIX}_{random.randint(1000, 9999)}")
        logger.info(f"订单创建:{order}")

        # 这里现在一定正常
        manager = JewelryWorkflowManager()
        final = manager.run(order)

        logger.info("=" * 60)
        logger.info(f"最终订单状态:{final}")
        logger.info("=== 系统运行完成 ===")

        '''
        logger.info("=== 珠宝定制系统启动 ===")

        # 1. 创建订单
        order = JewelryOrder(
            order_id=f"{ORDER_ID_PREFIX}_{random.randint(1000, 9999)}"
        )
        logger.info(f"订单创建:{order}")

        # 2. 执行全流程
        manager = JewelryWorkflowManager()
        final_order = manager.execute_full_workflow(order)

        # 3. 最终结果
        logger.info("=" * 60)
        logger.info(f"最终订单状态:{final_order}")
        logger.info("=== 系统运行完成 ===")
        time.sleep(1)
        '''

输出:

377fbd6f-ad97-43a2-9b74-e91cf7f75204

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)