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.5.tar.gz (10.7 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.5-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dotask-0.2.5.tar.gz
  • Upload date:
  • Size: 10.7 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.5.tar.gz
Algorithm Hash digest
SHA256 ace3e1f10184dfd159624441f3ab8264f0ca99a51a45e0371cb35493913ea0c0
MD5 8ab5ebaf91203f44531b2b702cfa5645
BLAKE2b-256 94e67fbf96ccc1be3fed725e62aa9bba99ac16fc171367d2c5a90f6a07f4bb3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dotask-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 11.1 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c4a1c4c075e22db39b2cca9c30788dfc075f4adbcbfda5a737e7b3c2f7a41b2e
MD5 4869c407fb0cb4f1f4589404de06a4aa
BLAKE2b-256 d5e3f878310bf9d0dc611368487b0b306f5ca2e818bd349fde369bd018ecec08

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