Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 气流将参数传递给相关任务_Bash_Airflow - Fatal编程技术网

Bash 气流将参数传递给相关任务

Bash 气流将参数传递给相关任务,bash,airflow,Bash,Airflow,在气流中,将参数传递到相关任务的方式是什么?我有很多bashs文件,我正在尝试将这种方法移植到aiffort,但我不知道如何在任务之间传递一些属性 这是一个真实的例子: #sqoop bash template sqoop_template = """ sqoop job --exec {{params.job}} -- --target-dir {{params.dir}} --outdir /src/ """

在气流中,将参数传递到相关任务的方式是什么?我有很多bashs文件,我正在尝试将这种方法移植到aiffort,但我不知道如何在任务之间传递一些属性

这是一个真实的例子:

#sqoop bash template
sqoop_template = """
        sqoop job --exec {{params.job}} -- --target-dir {{params.dir}} --outdir /src/
    """

s3_template = """
        s3-dist-cp --src= {{params.dir}} --dest={{params.s3}}
    """



#Task of extraction in EMR
t1 = BashOperator(
        task_id='extract_account', 
        bash_command=sqoop_template, 
        params={'job': 'job', 'dir': 'hdfs:///account/' + time.now().strftime("%Y-%m-%d-%H-%M-%S")},
        dag=dag)
#Task to upload in s3 backup.
t2 = BashOperator(
        task_id='s3_upload',
        bash_command=s3_template,
        params={}, #here i need the dir name created in t1
        depends_on_past=True
    )

t2.set_upstream(t1)
在t2中,我需要访问在t1中创建的dir名称

解决方案
这不是最终的解决方案,因此欢迎改进。谢谢。

查看XCOM-。这些用于任务之间的状态通信。

我认为气流不是用于管理状态的。您应该为任务使用DB来交换状态。

我认为,一种解决方案是使用t1中创建的属性创建一些文件,并在t2中使用相同的文件。我使用这种方法解决问题,但完全忘记在此处添加解决方案。谢谢
#Execute a valid job sqoop
def sqoop_import(table_name, job_name):
    s3, hdfs = dirpath(table_name)
    sqoop_job = job_default_config(job_name, hdfs)
    #call(sqoop_job)
    return {'hdfs_dir': hdfs, 's3_dir': s3}

def s3_upload(**context):
    hdfs = context['task_instance'].xcom_pull(task_ids='sqoop_import')['hdfs_dir']
    s3 = context['task_instance'].xcom_pull(task_ids='sqoop_import')['s3_dir']
    s3_cpdist_job = ["s3-dist-cp", "--src=%s" % (hdfs), "--dest=%s" % (s3)]
    #call(s3_cpdist_job)
    return {'s3_dir': s3} #context['task_instance'].xcom_pull(task_ids='sqoop_import')

def sns_notify(**context):
    s3 = context['task_instance'].xcom_pull(task_ids='distcp_s3')['s3_dir']
    client = boto3.client('sns')
    arn = 'arn:aws:sns:us-east-1:744617668409:pipeline-notification-stg'
    response = client.publish(TargetArn=arn, Message=s3)
    return response