I am trying to move files from my "new" folder in my-bucket to "test" folder in the same bucket using GCSToGCSOperator, I am passing a list of files to the source bucket but when I run dag I don't see files moving. I used xcom push to get list of file names from the folder new in my bucket
def segregate_files(ti):
source_bucket = "my-bucket"
PROJECT_ID="project"
destination_bucket = "my-bucket"
source_files=ti.xcom_pull(task_ids='list_file')
client = storage.Client(project=PROJECT_ID)
bucket = client.get_bucket(source_bucket)
print(source_files) #['new/abc.txt','new/bcd.txt','new/abc_bcd.txt']
new_files = [file for file in data if 'abc' in file]
print(new_files) #['new/abc.txt','new/abc_bcd.txt']
if new_files:
task_id = 'move_new_files'
move_abc_files = GCSToGCSOperator(
task_id=task_id,
source_bucket=source_bucket,
source_objects=new_files,
destination_bucket=destination_bucket,
destination_object="test/",
move_object=True,
dag=dag
)
bucket_files = GCSListObjectsOperator(
task_id='list_file',
bucket='my-bucket',
prefix='new/',
delimiter='.txt',
do_xcom_push=True,
dag=dag
)