Proposal: Support Class-Based Syntax for Python Entities
还没有人认领这个 Issue。
评估
调研方向
该 issue 没有指定任何文件或测试。首先检查 DurableEntityContext 周围现有的基于函数的实体处理方式以及链接的 TypeScript 示例,然后确定类方法、初始化、返回的结果和持久化状态应如何映射到当前实体模型。完成的前提是在实现之前就语法和状态处理设计达成一致。
由索引模型根据 Issue 内容生成。
描述
Currently, Entities in Python (and JavaScript) only support function-based syntax, where operations are delineated by a cascade of if-statements. In C#, a class-based syntax is supported, which allows individual operations to be split into methods belonging to a larger class that represents the Entity itself.
Implementing this alternative syntax should not be too difficult, it's mostly just a layer of indirection. Making matters simpler, we already have a community-driven example of how to do this for TypeScript here: https://scale-tone.github.io/2021/03/15/durable-mvc .
As an example for the syntax, consider the following entity function using the current implementation syntax
def entity_function(context: df.DurableEntityContext):
current_value = context.get_state(lambda: 0)
operation = context.operation_name
if operation == "add":
amount = context.get_input()
current_value += amount
elif operation == "reset":
current_value = 0
elif operation == "get":
pass
context.set_state(current_value)
context.set_result(current_value)
It's class-based syntax alternative would look as follows:
class Counter:
def __init__(self): # this corresponds to state initializer, or the `lambda: 0` in the function-based syntax
self.entity_state= 0
def add(self, amount):
self.entity_state+= amount
return self.entity_state
def get(self):
return self.entity_state
def reset(self):
return self.entity_state= 0
Finally, it makes sense to me that the return statement would set the value for context.set_result. A more difficult question is to know what value to save for set_state. One easy solution is to require the state to be under the name self.entity_state but perhaps that's too restrictive. What do others think?
- 主要语言
- Python
- 星标
- 157
- 派生
- 70
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Azure/azure-functions-durable-python 的其他 Issue
-
Enhancement fixed-in-v2 P3
难度 2/5 1-3 小时 新手友好度 72/100
Azure/azure-functions-durable-python#617 · 1 条评论 ·
-
bug Debuggability fixed-in-v2 P2
难度 2/5 1-3 小时 新手友好度 72/100
Azure/azure-functions-durable-python#587 · 2 条评论 · 1 个 reaction ·
-
Custom object serialization broken for orchestrator return values可能已有人在做 @andystaples 于 68 天前认领。 未关闭bug fixed-in-v2 P2
难度 2/5 1-3 小时 新手友好度 75/100
Azure/azure-functions-durable-python#568 · 1 条评论 ·
-
bug fixed-in-v2 P3
难度 2/5 1-3 小时 新手友好度 72/100
Azure/azure-functions-durable-python#475 · 1 条评论 ·
-
Enhancement fixed-in-v2 P3
难度 4/5 3-5 天 新手友好度 62/100
Azure/azure-functions-durable-python#618 · 1 条评论 ·
查看 Azure/azure-functions-durable-python 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
Vector35/community-plugins#376 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
py-econometrics/pyfixest#1883 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
ietf-tools/rfc2html#81 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
mysql/mysql-operator#60 ·
-
Python: Bug: split_plaintext_paragraph / split_markdown_paragraph can return a chunk larger than max_tokens可能已有人在做 @xThreeh 今天认领。 未关闭python triage
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/semantic-kernel#14566 ·
维护者通常 4 天内回复