【发布时间】:2020-04-06 19:30:06
【问题描述】:
我已经通过 Serverless 编写了 AWS Step 函数。逻辑如下所示
1. Execute Job
2. Get job status
3. Check if job succeeded
4. If not succeded wait for 60 seconds
目前,我已经编写了如下定义的阶跃函数
...
stepFunctions:
stateMachines:
myStateMachine:
definition:
states:
...
Execute Job:
...
Get Job Status:
Type: Task
Next: Is Job Succeeded?
# This job check if job is succeeded or not and sets a variable
# job_succeeded = true
Is Job Succeeded?
Type: Choice
Choices:
- Variable: "$.job_succeded"
BooleanEquals: true
Next: Next Lambda Function
Default: Wait for job
Wait for job:
Type: Wait
Seconds: 60
Next: Get Job Status
Next Lambda Function:
...
...
这非常有效!
但问题是,我必须为每个异步执行的每个不同作业编写 4 个 lambda,因此如果要完成 4 个此类任务,则将有 4 * 4 个步骤,即 16 个步骤。
这使得 step function 中看起来有很多 lambdas,很难看到实际的流程。
这4个功能可以概括为下面的伪代码
job_succeded = false
while job is not complete:
job_succeded = get_job_status()
if not job_succeded:
sleep 60 seconds
可能的解决方案是
stepFunctions:
stateMachines:
myStateMachine:
definition:
states:
...
Execute Job:
...
Get Job Status:
Type: RepeatWhile
Condition:
- Variable: "$.job_succeded"
BooleanEquals: true
Next: Next Lambda Function
WaitPeriod: 60 seconds
# This job check if job is succeeded or not and sets a variable
# job_succeeded = true
Next Lambda Function:
...
...
我知道这不是当前的情况,但这可以简化许多工作流程。 有没有其他方法可以简化这个?
【问题讨论】:
标签: python-3.x serverless-framework aws-step-functions