我在 Django celery 中有这样的任务:
@task
def file(password, source12, destination):
subprocess.Popen(['sshpass', '-p', password, 'rsync', '-avz', '--info=progress2', source12, destination],
stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[0]
我有一个执行上述任务的函数:
@celery.task
@login_required(login_url='/login_backend/')
def sync(request):
#user_id = request.session['user_id']
"""Sync the files into the server with the progress bar"""
if request.method == 'POST':
choices = request.POST.getlist('choice')
for i in choices:
new_source = source +"/"+ i
#b = result.successful()
#result.get() #Poll the database to get the progress
start_date1 = datetime.datetime.utcnow().replace(tzinfo=utc)
source12 = new_source.replace(' ', '') #Remove whitespaces
file.delay(password, source12, destination)
return HttpResponseRedirect('/uploaded_files/')
else:
return HttpResponseRedirect('/uploaded_files/')
我想向用户显示带有进度的文件传输信息。我想显示file name, remaining time and size of the file
正在传输的文件。我怎样才能做到这一点?