[英]Best practice handling parameter passed to multiple functions in classes and docstring
[英](Step Functions Activity Worker) Best practice for handling long polling timeouts in boto?
我正在從事我的第一步功能活動工作者(EC2)。 可以預期,經過5分鍾的長時間輪詢后,Step Functions狀態機沒有任何活動,客戶端連接超時並顯示以下錯誤:
botocore.exceptions.ReadTimeoutError:在端點URL上讀取超時:“ https://states.us-east-1.amazonaws.com/ ”
捕獲錯誤並重試長輪詢(如果沒有活動,則每5分鍾重試一次),還是嘗試盡早終止呼叫並在錯誤之前重試,會更好? 我曾考慮過使用另一種類型的循環,但是我想最大化長輪詢的值,而不是針對Step Functions API反復請求(盡管如果這樣做是最好的方式)。
謝謝,
安德魯
import boto3
import time
import json
region = 'us-east-1'
activity_arn = 'arn:aws:states:us-east-1:754112345676:activity:Process_Imagery'
while True:
client = boto3.client('stepfunctions', region_name=region)
response = client.get_activity_task(activityArn=activity_arn,
workerName='imagery_processor')
activity_token = response['taskToken']
input_params = json.loads(response['input'])
print("================")
print(input_params)
client.send_task_success(taskToken=activity_token, output='true')
我相信我在這里回答了我自己的問題。 AWS文檔指出 :“服務在響應之前保留請求的最長時間為60秒。如果60秒內沒有可用任務,則輪詢將返回帶有空字符串的taskToken。”
但是,我相信不是來自返回字符串,而是來自StepFunctions的JSON響應根本沒有'taskToken'。 while循環有效:
import boto3
import time
import json
from botocore.config import Config as BotoCoreConfig
region = 'us-east-1'
boto_config = BotoCoreConfig(read_timeout=70, region_name=region)
sf_client = boto3.client('stepfunctions', config=boto_config)
activity_arn = 'arn:aws:states:us-east-1:754185699999:activity:Process_Imagery'
while True:
response = sf_client.get_activity_task(activityArn=activity_arn,
workerName='imagery_processor')
if 'taskToken' not in response:
print('No Task Token')
# time.sleep(2)
else:
print(response['taskToken'])
print("===================")
activity_token = response['taskToken']
sf_client.send_task_success(taskToken=activity_token, output='true')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.