microsoft / microsoft/durabletask-python

Add Durable Task middleware support

未关闭
#136 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
40
派生
33
平均合并
2 天 2 小时
30 天内合并 PR
6

描述

Summary

Track adding SDK-level Durable Task middleware support to the Python SDK, aligned with the .NET reference implementation.

Reference spec: https://github.com/microsoft/durabletask-dotnet/blob/feature/durable-task-middleware/doc/cross-sdk-middleware.md
.NET user guide: https://github.com/microsoft/durabletask-dotnet/blob/feature/durable-task-middleware/doc/durable-task-middleware.md
Motivation: https://github.com/Azure/azure-functions-durable-extension/issues/3054

The spec may shift until the .NET v1 implementation is merged. This issue is intended to track the Python design and implementation work so it can follow the same durable middleware contract with idiomatic API names.

Proposed shape

Names are illustrative, not final API commitments.

@app.orchestration_middleware
async def orchestration_middleware(ctx, next):
    if not ctx.is_replaying:
        ctx.logger.info("starting orchestration", extra={"instance_id": ctx.instance_id})

    await next(ctx)

@app.activity_middleware
async def activity_middleware(ctx, next):
    cached = await cache.try_get(ctx.name, ctx.input)
    if cached is not None:
        ctx.set_result(cached)
        return

    await next(ctx)

Design points to cover

  • Decorator and/or builder registration APIs that are scoped to a worker/app instance.
  • Registration ordering: first registered middleware runs outermost and unwinds last.
  • Dataclass/protocol-style contexts that expose durable task name, instance ID, version/parent/tags where available, input, raw input where available, replay state for orchestrations, features, and result after next.
  • A feature collection using type keys or well-known keys when runtime type identity is not the right Python abstraction.
  • Orchestration middleware determinism guidance for replay, including replay-safe logging and avoiding datetime.now, uuid.uuid4, random, file/network I/O, arbitrary asyncio awaits, and mutable process state.
  • Activity middleware short-circuiting through an explicit set_result API.
  • Host integration pattern for Azure Functions or other hosts to attach invocation context through features instead of durable middleware depending on host middleware internals.

Acceptance criteria

  • Orchestration and activity middleware APIs are exposed at the durable worker/app level.
  • Middleware executes in registration order and unwinds in reverse order.
  • Orchestration middleware must call next(ctx) exactly once when completing successfully; missing or duplicate calls are rejected where feasible.
  • Activity middleware can call next(ctx) once or short-circuit only through ctx.set_result(...); duplicate next is invalid.
  • Host-specific objects can be passed through features without serialization into durable history.
  • Documentation covers replay determinism and the difference between durable middleware and host/Functions middleware.
  • Tests cover registration ordering, context population, feature access, orchestration next-call validation, and activity short-circuiting.
  • No wire protocol or protobuf changes are required.
  • Entity middleware is out of scope for v1.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先比较所引用的 .NET cross-SDK middleware specification 和 user guide,然后定位 Python durable worker/app registration entry points。定义 orchestration 和 activity APIs、contexts、feature access、ordering、validation 以及 short-circuit behavior,并添加 acceptance-criteria tests 和 documentation;entity middleware 和 wire changes 不在范围内。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend-api-design, distributed-systems
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
32/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。