Skip to main content

发布订阅注解方式

Project description

版本说明

0.1.0

  • 在方法上添加@task就可以直接开启一个线程执行任务
  • 常用参数:
    • 生产者: role="producer",topic="自定义"
    • 消费者: role="consumer",subscribe="自定义",publish_after="自定义"
  • 说明:
    • role: 用于区分上下游 producer/consumer
    • topic: 发布的主题
    • subscribe: 对哪些主题感兴趣
    • publish_after: 消费完后继续发布新主题
  • 特别的:方法的返回值可以进行传递,若没有返回值则不会发布新主题(只针对消费者和消费者之间)

0.2.x

  1. dotask暴露topic_manager=>可以更好的管理生产消费者
  2. 迁移logger至util包下
  3. 添加本地调用shell工具函数->可以很好的适配@task消费者
    1. max_concurrent:控制并发执行的shell数量
    2. 引入dotask.Shell 调用Shell(max_concurrent=?).local_shell_execute(cmd,callback)来使用

快速开始

安装

pip install dotask

示例

  1. 简单的生产发布模式
from dotask import task  
from dotask.util import logger  
import random  
  
if __name__ == '__main__':  
  
    @task(role="producer",topic="scan")  
    def a():  
        return random.randint(1,10)  
  
  
    @task(role="consumer",subscribe="scan",publish_after="sayHi")  
    def b(data):  
        if data >5:  
            return data  
        logger.warning(f"本次生成数字:{data},不会继续发布sayHi主题")  
  
    @task(role="consumer",subscribe="sayHi")  
    def c(data):  
        logger.debug(f"c触发")  
        logger.info(f"消费:{data}")
//=====================================================================
2026-02-08 17:30:37 - INFO - 发布主题-[scan]:5
2026-02-08 17:30:37 - WARNING - 本次生成数字:5,不会继续发布sayHi主题
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:8
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:8
2026-02-08 17:30:38 - DEBUG - c触发
2026-02-08 17:30:38 - INFO - 消费:8
2026-02-08 17:30:38 - INFO - 发布主题-[scan]:6
2026-02-08 17:30:38 - INFO - 发布主题-[sayHi]:6
2026-02-08 17:30:38 - DEBUG - c触发
2026-02-08 17:30:38 - INFO - 消费:6
//======================================================================

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotask-0.2.4.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotask-0.2.4-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file dotask-0.2.4.tar.gz.

File metadata

  • Download URL: dotask-0.2.4.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for dotask-0.2.4.tar.gz
Algorithm Hash digest
SHA256 cb4102cdb1f645b59be7d9e21a4a39c14f92ccc6d467e64d78029f2a9c70daa5
MD5 e8fed1f9fadff4be2560d4b2e07f7e77
BLAKE2b-256 55f909124a05dcce1be5d8995feb71aef7a5d052154bd1553fba6c690284b580

See more details on using hashes here.

File details

Details for the file dotask-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: dotask-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for dotask-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a2415f6db36d1c18c9a011ee246120888ff4b9c28ada826ecab312952c918180
MD5 1addc02673c8264332e2a007bf65f939
BLAKE2b-256 2551b522ca5332205758f68834058d2213620a5917a92541bc9f574372a30806

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page