這幾天備考aws saa,所以比較少時間撰寫內容,之後會統一更新。
flyte除了使用pyflyte run 與 透過UI啟動外,也可以透過SDK啟動workflow。
將原本mean_value_wf新增remote物件,並給予config設定與workflow,便能提交並獲取執行結果。
Config.auto會使用與pyflyte相同的環境變數。如FLYTECTL_CONFIG。
# python mean_value_wf.py提交即可
import flytekit as fl
from typing import List
import random
from flytekit.configuration import Config
@fl.task()
def gen_nums(low: int, high: int, length: int) -> List[int]:
return [random.randint(low, high) for _ in range(length)]
@fl.task()
def mean(nums: List[int]) -> float:
return sum(nums) / len(nums)
@fl.workflow()
def mean_val_wf(low: int = 0, high: int = 100, length: int = 100) -> float:
arr = gen_nums(low, high, length)
mean_val = mean(arr)
return mean_val
remote = fl.FlyteRemote(
config=Config.auto(),
default_project="flytesnacks",
default_domain="development"
)
remote.fast_register_workflow(entity=mean_val_wf)
execution = remote.execute(
entity=mean_val_wf,
inputs={"low": 10, "high": 20, "length": 200},
wait=True,
)
output = execution.outputs["o0"]
print(output)
畫面如下