小编ada*_*n11的帖子

Airflow - 在同一 DAG 中使用 TaskGroup 和 PythonBranchOperator

我目前正在使用 Airflow Taskflow API 2.0。我在结合使用 TaskGroup 和 BranchPythonOperator 时遇到问题。

下面是我的代码:

import airflow
from airflow.models import DAG
from airflow.decorators import task, dag
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import BranchPythonOperator, PythonOperator
from airflow.operators.python import task, get_current_context
from random import randint
from airflow.utils.task_group import TaskGroup


default_args = {
    'owner': 'Airflow',
    'start_date': airflow.utils.dates.days_ago(2),
}

@task
def dummy_task():
    return {}


@task
def task_b():
    return {}

@task
def task_c():
    return {}

def final_step():
    return {}

def get_tasks(**kwargs):
    task = 'task_a'

    return task


with DAG(dag_id='branch_dag', 
    default_args=default_args, …
Run Code Online (Sandbox Code Playgroud)

airflow airflow-scheduler

10
推荐指数
1
解决办法
9080
查看次数

PyMUPDF - 如何将 PDF 转换为图像,使用图像大小的原始文档设置并设置为 300dpi?

我目前正在考虑使用 python 包 PyMuPDF 来实现将 PDF 转换为图像的工作流程(在我的例子中,为 .TIFF 文件)。

我正在尝试模仿我当前用于 PDF -> 图像转换的另一个程序的行为。在该程序中,它允许您设置成像设置,如下所示:

图像输出质量 (DPI):(默认为 300dpi)

基本图像尺寸:原始设置 - 使用原始文档设置渲染图像。

我的问题是,这在 PyMuPDF 中可能吗?如何将图像的输出 DPI 设置为 300 并将图像大小设置为原始文档大小?我对处理 PDF/图像的这种处理还很陌生,因此我们将不胜感激。

提前致谢,

pymupdf

10
推荐指数
1
解决办法
8450
查看次数

Psycopg2 - 使用连接字符串连接到 postgreSQL 数据库

我目前有一个格式为的连接字符串:

"localhost://username:password@data_quality:5432"
Run Code Online (Sandbox Code Playgroud)

使用 psycopg2 连接到我的数据库的最佳方法是什么?例如:

connection = psycopg2.connect(connection_string)
Run Code Online (Sandbox Code Playgroud)

python psycopg2

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

Airflow - 如何处理异步 API 调用?

我正在尝试找出如何最好地解决以下问题。本质上,我有一个外部 API 服务,我向其发送请求并获取结果。

POST = 发送请求,您收到的响应是一个 URL,您可以使用该 URL 进行 GET 请求来检索结果。

GET = 轮询 POST 请求返回的 URL,直到获得成功结果。

在气流中解决这个问题的最佳方法是什么?我的想法是本质上有两个任务并行运行。

  1. 一种发送 POST 请求,然后将响应 URL 保存到 XCOM。
  2. 另一个将在 while 循环中持续运行,从 XCOM 存储中读取新的 URL 响应并获取响应。一旦从该 URL 成功检索到结果,它就会从 XCOM 存储中删除。

您认为这是正确的处理方式吗?或者我应该使用 python 中的 asyncio 库吗?

非常感谢任何帮助

谢谢,

airflow

5
推荐指数
1
解决办法
3027
查看次数

Python-Requests库-如何确保HTTPS请求

这可能是一个愚蠢的问题,但我只想确认以下内容。

我目前正在 python 中使用 requests 库。我使用它来调用托管在 Azure 云上的外部 API。

如果我使用虚拟机中的请求库,并且请求库发送到 URL:https : //api-management-example/run,这是否意味着我与此 API 的通信以及我发送的整个有效负载安全吗?我在虚拟环境中的 Python 站点包中看到,有一个 cacert.pem 文件。我需要更新吗?我是否需要做其他事情来确保通信安全,或者我调用 HTTPS URL 就意味着它是安全的?

任何信息/指导将不胜感激。

谢谢,

python python-requests python-requests-html

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