【发布时间】:2013-02-05 05:46:45
【问题描述】:
我在 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。我该怎么做?
【问题讨论】:
标签: django django-celery