小编Ale*_*glo的帖子

如果我在任务中发送 http 请求,为什么我的 Airflow 会挂起?

系统: MacOS Apple M1(本机)

气流: 2.5.3

执行器:带有 Postgres 数据库的本地

我正在尝试实现一些外部触发的工作流程,这些工作流程从我们的 REST API 加载数据。我正在使用 Python Operator 运行代码并使用 Airflow UI 手动触发该流程。然而,当执行到包含发送 http 请求的代码的任务时,它会永远挂起,并且笔记本电脑开始运行得非常热。

在此输入图像描述

在此输入图像描述

该任务在另一个文件中定义,我将其作为模块导入。以下是任务文件(tasks/import_logs.py)的内容

import requests

def import_logs(**context):
    print("[Sasha] Running log importer")
    context["ti"].xcom_push(
        key="logs", value=["log/location/1", "log/location/2"])
    print("Log locations pushed to xcom")
    # Define the URL for the dummy endpoint
    url = 'https://jsonplaceholder.typicode.com/posts'

    # Define the payload for the JSON request
    payload = {
        "title": "foo",
        "body": "bar",
        "userId": 1
    }

    # Define the headers for the request
    headers = {'Content-Type': 'application/json'} …
Run Code Online (Sandbox Code Playgroud)

python airflow airflow-2.x

2
推荐指数
1
解决办法
1182
查看次数

标签 统计

airflow ×1

airflow-2.x ×1

python ×1