How to use return value (str) of one activity as input a second activity in temporal python sdk?

huangapple go评论56阅读模式
英文:

How to use return value (str) of one activity as input a second activity in temporal python sdk?

问题

我要翻译的部分:

"I'm using the python sdk for https://temporal.io/.
I have a workflow that i'd like to execute two sequential activities.

  1. Do X and return a filepath.
  2. Do Y with data at that filepath.

How do i get path_from_previous_activity from the first activity?!!"

英文:

I'm using the python sdk for https://temporal.io/.
I have a workflow that i'd like to execute two sequential activities.

  1. Do X and return a filepath.
  2. Do Y with data at that filepath.
@workflow.defn
class ScraperWorkflow:
    @workflow.run
    async def run(self, scraper_input: ScraperInput):
        
        scraper_result = await workflow.execute_activity(
            ercot_scraper, # activity that takes scraper_input and returns a path
            scraper_input,
        )
 
        extractor_result = await workflow.execute_activity(
            extract_activity,
            path_from_previous_activity,
        )
        return 

How do i get path_from_previous_activity from the first activity?!!

答案1

得分: 2

你的请求是:

"What do you mean with "path_from_previous_activity"?
You can pass the results of your fist activity as input to the second one. so can pass scraper_result as input to your extract_activity."

以下是翻译好的部分:

你的问题是:

"你是什么意思的 "path_from_previous_activity"?
你可以将第一个活动的结果作为输入传递给第二个活动。所以可以将 scraper_result 作为输入传递给你的 extract_activity。"

英文:

What do you mean with "path_from_previous_activity"?

You can pass the results of your fist activity as input to the second one. so can pass scraper_result as input to your extract_activity.

答案2

得分: 1

If I’m understanding your question correctly it seems like you want both activities to run on the same machine. That doesn’t happen by default with Temporal, each activity attempt may run on a different host. You can leverage the sticky activity pattern to ensure activities run on the same host.

如果我理解你的问题正确,似乎你想让两个活动在同一台机器上运行。这在 Temporal 中不是默认行为,每个活动尝试可能会在不同的主机上运行。你可以利用粘性活动模式来确保活动在同一主机上运行。

If you want to return a FilePath object, I believe that’s not serializable by default, there are different ways to handle this, the easiest of them being passing paths as strings. I recommend returning a dataclass from the activity that contains both the result and the path so you can extend it if need be in a backwards compatible manner.

如果你想返回一个 FilePath 对象,我认为默认情况下它是不可序列化的,处理它有不同的方法,其中最简单的方法是将路径作为字符串传递。我建议从活动中返回一个数据类,其中包含结果和路径,这样你可以以向后兼容的方式扩展它。

链接地址

英文:

If I’m understanding your question correctly it seems like you want both activities to run on the same machine.
That doesn’t happen by default with Temporal, each activity attempt may run on a different host.
You can leverage the sticky activity pattern to ensure activities run on the same host.

If you want to return a FilePath object, I believe that’s not serializable by default, there are different ways to handle this, the easiest of them being passing paths as strings.
I recommend returning a dataclass from the activity that contains both the result and the path so you can extend it if need be in a backwards compatible manner.

https://github.com/temporalio/samples-python/tree/main/activity_sticky_queues

huangapple
  • 本文由 发表于 2023年4月7日 02:28:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定