I have DAG in first.py: with DAG( defaultargs={ 'owner': CONFIG['dagowner'], 'retries':…
- User
I have DAG in first.py: with DAG( default_args={ 'owner': CONFIG['dag_owner'], 'retries': CONFIG['dag_retries'], 'retry_delay': CONFIG['dag_retry_delay'] }, dag_id = 'Weather_ETL', description='Download archive data for Moscow Weather', start_date=datetime(2023, 9, 1), schedule_interval='0 1/3 * * *', catchup=False ) as dag: Weather_etl = DockerOperator( task_id="weather_etl", image="weather-etl:latest", command="python main.py", docker_url='unix://var/run/docker.sock', mount_tmp_dir = False, auto_remove=True, xcom_all=True )
and main.py that placed in docker container:
def main():
kotlin Copy code file_path = extract()
data = transform(file_path)
If new data is found, add to DB
if data.shape[0] > 0: load(data) new_rows_found = True else: new_rows_found = False
first.py and main.py are different files i need to save new_rows_found to xcom of airflow
- Assistant
To save the
new_rows_foundvariable to the XCom of Airflow, you can use thexcom_pushattribute of theDockerOperatortask in your DAG.Here's an updated version of your code in the
first.pyfile:from datetime import datetime from airflow import DAG from airflow.operators.docker_operator import DockerOperator with DAG( default_args={ 'owner': CONFIG['dag_owner'], 'retries': CONFIG['dag_retries'], 'retry_delay': CONFIG['dag_retry_delay'] }, dag_id='Weather_ETL', description='Download archive data for Moscow Weather', start_date=datetime(2023, 9, 1), schedule_interval='0 1/3 * * *', catchup=False ) as dag: Weather_etl = DockerOperator( task_id="weather_etl", image="weather-etl:latest", command="python main.py", docker_url='unix://var/run/docker.sock', mount_tmp_dir=False, auto_remove=True, xcom_all=True, xcom_push=True # Enable XCom push )
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.