Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BF403200CDF for ; Wed, 26 Jul 2017 00:58:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BDC39167138; Tue, 25 Jul 2017 22:58:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0B13A167103 for ; Wed, 26 Jul 2017 00:58:06 +0200 (CEST) Received: (qmail 28190 invoked by uid 500); 25 Jul 2017 22:58:06 -0000 Mailing-List: contact dev-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list dev@airflow.incubator.apache.org Received: (qmail 28178 invoked by uid 99); 25 Jul 2017 22:58:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Jul 2017 22:58:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 432981806DB for ; Tue, 25 Jul 2017 22:58:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.479 X-Spam-Level: ** X-Spam-Status: No, score=2.479 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=credijusto-com.20150623.gappssmtp.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id ber4cXPtRYlj for ; Tue, 25 Jul 2017 22:58:03 +0000 (UTC) Received: from mail-vk0-f54.google.com (mail-vk0-f54.google.com [209.85.213.54]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id AA31D5FD06 for ; Tue, 25 Jul 2017 22:58:02 +0000 (UTC) Received: by mail-vk0-f54.google.com with SMTP id n125so12374708vke.1 for ; Tue, 25 Jul 2017 15:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=credijusto-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=KlNPeCFQ4mxtKaFBecwLDQecIuf3T0pZWerizsiq8XU=; b=m5cuQmY8Lgox0WKWAX7upHQ/Rf9aWFeAEr7CncUFVs99PNUNv+kvDBtaXQguECRp2/ E1t4vVIxZ2t51RlUhyNHBts+Vh689Wshb5zCnaq9/inU97TpstWlKrFAuWOanTiqLtHT qeRMnJUugq+mX0u4H4AmBncpKdQS1dS8ZC6NrorPy7ThqOqgXvtJzbNUov19Zhq2TA3T qEbdkezteyXOJcYgA/IIQfsVnqjX/TlI+vtbCbc3FLEHrvKCAKCB4ZwKKyVOk4o04l7t PC4hdjua+MIOlPGwPd1PxEUMoAZeKsXuihaxH4pCx0t7aWJQb+wGKC6sJFW/O0pHdTNU hVIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=KlNPeCFQ4mxtKaFBecwLDQecIuf3T0pZWerizsiq8XU=; b=TeORO6F2cT+MwCzLAqQGFYo6iMAu42IP1/fSnt3pM4H2jFsnsDtsEMun/A2C+JNlgf drAaSaLdDbpKs72nvKBUbT0d+th75pnRBEr25+coBnvE9Zr3zu8wmHhM//KzWgOeSnbM wy8bXNr4IgguxYb7s4PS1xXkf9QwoUvkBwwCBi/L4ccsREtjqktm5agtxngkPcU5CThE xqYAPcOLhFFtaT/4EY8aIHsP+xbCaMdNNksVJmUS/7W+Kdm578KLHl1xoYhq3JHBQS02 gmGfNJrXISzs88lpXjV0+uG/9DMEQJrFooTv1dIn5ztUlUL+N0zOQR0ylkwYFhT2C9BI 5B7g== X-Gm-Message-State: AIVw111R4mVK4JMXgItWAE0UfE9c7aBXaEfG8+1n3Jy0vdtUGOHWbzP2 xi0qklLnqyXvtLAbBp+pINy8kjfh1WqMkUtHjrG6Gi1ZG7qBI4SEG/bD2l2kaR1Pwo04taP7Njc s8VB1ro5E0tcb5eLu5pwNHbiFQmj7A2bM6z4= X-Received: by 10.31.7.211 with SMTP id 202mr11006806vkh.212.1501023481883; Tue, 25 Jul 2017 15:58:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.70.97 with HTTP; Tue, 25 Jul 2017 15:58:01 -0700 (PDT) From: Aaron Polhamus Date: Tue, 25 Jul 2017 15:58:01 -0700 Message-ID: Subject: How to make DAGs dynamic based on task output To: dev@airflow.incubator.apache.org Content-Type: multipart/alternative; boundary="001a11457ec6701d0d05552c43a3" archived-at: Tue, 25 Jul 2017 22:58:07 -0000 --001a11457ec6701d0d05552c43a3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable This question was posted on StackOverflow here: https://stackoverflow.com/questions/45314174/how-to-dynamically-iterate-ove= r-the-output-of-an-upstream-task-to-create-paralle Consider the following example of a DAG where the first task, get_id_creds, extracts a list of credentials from a database. This operation tells me what users in my database I am able to run further data preprocessing on and it writes those ids to the file /tmp/ids.txt. I then scan those ids into my DAG and use them to generate a list of upload_transaction tasks that can be run in parallel. My question is: Is there a more idiomatically correct, dynamic way to do this using airflow? What I have here feels clumsy and brittle. How can I directly pass a list of valid IDs from one process to that defines the subsequent downstream processes? from datetime import datetime, timedeltaimport osimport sys from airflow.models import DAGfrom airflow.operators.python_operator import PythonOperator import ds_dependencies SCRIPT_PATH =3D os.getenv('DASH_PREPROC_PATH')if SCRIPT_PATH: sys.path.insert(0, SCRIPT_PATH) import dash_workerselse: print('Define DASH_PREPROC_PATH value in environmental variables') sys.exit(1) default_args =3D { 'start_date': datetime.now(), 'schedule_interval': None} DAG =3D DAG( dag_id=3D'dash_preproc', default_args=3Ddefault_args) get_id_creds =3D PythonOperator( task_id=3D'get_id_creds', python_callable=3Ddash_workers.get_id_creds, provide_context=3DTrue, dag=3DDAG) with open('/tmp/ids.txt', 'r') as infile: ids =3D infile.read().splitlines() for uid in uids: upload_transactions =3D PythonOperator( task_id=3Duid, python_callable=3Ddash_workers.upload_transactions, op_args=3D[uid], dag=3DDAG) upload_transactions.set_downstream(get_id_creds) Thanks in advance! --=20 *Aaron Polhamus* *Director of Data Science * Cel (M=C3=A9xico): +52 (55) 1951-5612 Cell (USA): +1 (206) 380-3948 Tel: +52 (55) 1168 9757 - Ext. 181 --=20 ***Por favor referirse a nuestra p=C3=A1gina web=20 para m=C3=A1s informaci= =C3=B3n=20 acerca de nuestras pol=C3=ADticas de privacidad.* --001a11457ec6701d0d05552c43a3--