使用 Airflow,在同一个循环中,成功的 API 响应继续执行下一个任务,但有错误的响应有单独的任务,显示为失败

using Airflow, from the same loop an API response with success continue to next task but a response w/ error has separate task that shows as failed

我想知道是否有好的方法来执行此操作,我有下面的循环,它列出了所有抛出错误的 Facebook 页面:

permission_error =[]
for idx, series in df.iterrows():
    id = series['id']
    access_token = series['access_token']
    response = requests.get(url=f'https://graph.facebook.com/{id}/feed?fields=insights.metric(post_impressions_unique,post_impressions)&since=2021-06-01&until=2021-06-20&access_token={access_token}')
    json_response = response.json()
    if 'error' in json_response:
        permission_error(series['name'])

什么是分解任务的最佳方式,以便 运行 的页面成功继续执行下一个任务,但可能类似于单独的任务,显示 'success' 以外的所有内容json_response 中的 'error' 条消息。如果是这样,最好的方法是什么?

如果页面数量少,您可以 return 它们作为两个单独的字典存储在 XCom 中,使用不同的键(通过 xcom.push() 并在两个任务中从 xcom 中提取不同的键关注

如果页面数量在 1000 秒左右,那么最好将这些 URLS 作为两个不同的对象写入外部存储(如 GCS/S3),并通过设置这些对象的名称那两个 XCom 键。