我需要通过 ftp 下载文件,更改它并上传回来。我正在使用 celery 来执行此操作,但是在尝试使用链接时遇到了问题,我得到了:
TypeError:upload_ftp_image() 正好需要 5 个参数(给定 6 个)
另外,我可以使用链并确保这些步骤是连续的吗?如果不是,还有什么选择?
res = chain(download_ftp_image.s(server, username , password, "/test_app_2/model.dae" ,"tmp/test_app_2/"), upload_ftp_image.s(server, username , password, "tmp/test_app_2/model.dae" ,"tmp/test_app_2/")).apply_async()
print res.get()
任务:
@task()
def download_ftp_image(ftp_server, username , password , filename, directory):
try:
ftp = FTP(ftp_server)
ftp.login(username, password)
if not os.path.exists(directory):
os.makedirs(directory)
ftp.retrbinary("RETR /default_app/model.dae" , open(directory + 'model.dae', 'wb').write)
else:
ftp.retrbinary("RETR /default_app/model.dae" , open(directory + 'model.dae', 'wb').write)
ftp.quit()
except error_perm, resp:
raise download_ftp_image.retry(countdown=15)
return "SUCCESS: "
@task()
def upload_ftp_image(ftp_server, username , password , file , directory):
try:
ftp = FTP(ftp_server)
ftp.login(username, password)
new_file= file.replace(directory, "")
directory = directory.replace("tmp","")
try:
ftp.storbinary("STOR " + directory + new_file , open(file, "rb"))
except:
ftp.mkd(directory)
ftp.storbinary("STOR " + directory + new_file, open(file, "rb"))
ftp.quit()
except error_perm, resp:
raise upload_ftp_image.retry(countdown=15)
return "SUCCESS: "
对于我的具体情况,这是好的还是坏的做法?:
result = download_ftp_image.apply_async((server, username , password, "/test_app_2/model.dae" ,"tmp/test_app_2/",), queue='rep_data')
result.get()
result = upload_ftp_image.apply_async((server, username , password, "tmp/test_app_2/model.dae" ,"tmp/test_app_2/",), queue='rep_data')
#result.get()