这是 Python/转换的用例吗?
假设我的(asyncio)工作流程是这样的:
- A = aiohttp.get(url_a) (重试 n 次,每次重试超时)
- B = aiohttp.get(url_b) (重试 n 次,每次重试超时)
- 如果我得到了A& B-> 保存到数据库
- 如果我得到 A 但没有 B -> 则 ->如果我得到 B 但没有 A,则估算 B 并保存到数据库
- -> 如果我没有 A 也没有 B,则估算 A 并保存到数据库
- ->估算 A,估算 B,保存到数据库
- aiohttp.post(url_x) (A, B)
基本上,我试图获取 A 和 B,但我可能会以 4 种不同的情况结束:获取 A 和 B,获取 A 但不获取B,得到B但得不到A,什么也得不到。不管怎样,超时后,我必须知道我得到了什么,并继续输入缺失值(如果有)并保存到数据库。当我说插补时,它过于简单化了。实际上,我需要某种分支,检查输入并选择分支(类似于 if)。记录成功保存到数据库后,A和B应该发布到url_x。
这样的工作流程是(py)转换状态机的用例吗?如果是这样,是否有任何示例与我刚才描述的场景有点相似?作为状态机概念的新手,我什至不知道这里是什么状态以及什么是转换。
Let's say that my (asyncio) workflow is like this:
- A = aiohttp.get(url_a) (with n retries and timeout of each retry)
- B = aiohttp.get(url_b) (with n retries and timeout of each retry)
- if I got A & B -> save to the database
- if I got A but not B -> impute B and save to the database
- if I got B but not A -> impute A and save to the database
- if I haven't got A nor B -> impute A, impute B, save to the database
- aiohttp.post(url_x) (A, B)
Basically, I am trying to get A and B, but I could end in 4 different situations: get A and B, get A but not B, get B but not A and cannot get anything. Anyway, after timeout, I must know what I have got and continue with imputing missing values (if any) and saving to the database. When I say imputing, it is oversimplified. Actually, I need some kind of branching, checking inputs and choosing branch (something like if). After the record is successfully saved to the database, A and B should be posted to url_x.
Is such workflow an use case for (py)transitions state machine? If so, is there any example that is a bit alike the scenario I have just described? As a novice to the state machine concept, I don't even know what states are here and what are transitions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论