Ich schreibe eine Airflow -Aufgabe zum Lesen eines großen CSV und speichern Sie sie in der PostGRESQL -Datenbank. Es ist jedoch asynchron und ich weiß nicht, wie ich es in den Luftstrom einbezieht.from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
from pandas import DataFrame
import asyncpg
async def to_sql(dataframe, table_name, schema_name='public', timeout=None, truncate=False):
connection = await asyncpg.connect(user='postgres', host='host.docker.internal', database='quantaxis', password='123456')
result = await connection.copy_records_to_table(
table_name,
records=dataframe.values.tolist(),
columns=shared_columns,
schema_name=schema_name,
timeout=timeout)
await connection.close()
return result
default_args = {
'owner': 'Airflow',
'depends_on_past': False,
'start_date': datetime(2020, 1, 1),
'retries': 1,
'retry_delay': timedelta(minutes=1),
}
dag = DAG('pythonexp2123', default_args=default_args, schedule_interval=timedelta(days=1))
async def save_file_to_database(ds):
df = pd.read_csv("data{0}.csv".format(ds))
r = await to_sql(df, 'test')
return r
t1 = PythonOperator(
task_id='pushing_task',
provide_context=True,
python_callable=save_file_to_database,
dag=dag
)
t1
< /code>
Wenn ich es ausführe, gibt es Fehler zurück: < /p>
Can't Pickle Object
< /code>
Wie könnte ich die Funktion ändern, damit diese DAG funktioniert? Ich möchte wegen seiner Geschwindigkeit immer noch ein asyncpg -Paket verwenden.
Wie fahre ich eine asynchronisierte Funktion im Luftstrom aus? ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post
-
-
So konvertieren Sie die asynchronisierte Funktion/Methode in den Verlag in SWIFT6
by Anonymous » » in IOS - 0 Replies
- 8 Views
-
Last post by Anonymous
-