2
votes

I can run the single file as a dataflow job in cloud composer but when i run it as a package it fails .

pipeline_jobs/
-- __init__.py
-- run.py  (main file)
-- setup.py 
-- data_pipeline/
----- __init__.py
----- tasks.py
----- transform.py
----- util.py

I'm getting this error:

WARNING -  File "/tmp/dataflowd232f-run.py", line 14, in <module
{gcp_dataflow_hook.py:120} WARNING - from data_pipeline.tasks import task
WARNING - ImportError: No module named data_pipeline.tasks.

This is the dag configuration:

from datetime import datetime, timedelta
from airflow import DAG
from airflow.contrib.operators.dataflow_operator import DataFlowPythonOperator

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime.strptime("2017-11-01","%Y-%m-%d"),
    'py_options': [],
    'dataflow_default_options': {
        'start-date': '20171101',
        'end-date': '20171101',
        'project': '<project-id>',
        'region': '<location>',
        'temp_location': 'gs://<bucket>/flow/tmp',
        'staging_location': 'gs://<bucket>/flow/staging',
        'setup_file': 'gs://<bucket>/dags/pipeline_jobs/setup.py',
        'runner': 'DataFlowRunner',
        'job_name': 'job_name_lookup',
        'task-id': 'run_pipeline'
    },
}

dag = DAG(
    dag_id='pipeline_01',
    default_args=default_args,
    max_active_runs=1,
    concurrency =1
)

task_1 = DataFlowPythonOperator(
    py_file = 'gs://<bucket>/dags/pipeline_jobs/run.py',
    gcp_conn_id='google_cloud_default',
    task_id='run_job',
    dag=dag)

I tried putting run.py into dags folder but still getting same error. Any kind of suggestions would be really helpful.

Tried doing this as well: from pipeline_jobs .data_pipeline.tasks import task but still the same issue.

1

1 Answers

3
votes

Try put the entire pipeline_jobs/ in dags folder following this instruction and refer the dataflow py file as: /home/airflow/gcs/dags/pipeline_jobs/run.py.