我有一个 django celery 视图,它执行某些任务,并在任务成功完成后将其写入数据库。
我正在这样做:
result = file.delay(password, source12, destination)
和,
if result.successful() is True:
#writes into database
但是在任务完成执行后,它不会进入 if 条件。我试过result.ready()
但没有运气。
编辑:以上几行在同一个视图中:
def sync(request):
"""Sync the files into the server with the progress bar"""
choice = request.POST.getlist('choice_transfer')
for i in choice:
source12 = source + '/' + i
start_date1 = datetime.datetime.utcnow().replace(tzinfo=utc)
start_date = start_date1.strftime("%B %d, %Y, %H:%M%p")
basename = os.path.basename(source12) #Get file_name
extension = basename.split('.')[1] #Get the file_extension
fullname = os.path.join(destination, i) #Get the file_full_size to calculate size
result = file.delay(password, source12, destination)
if result.successful() is True:
#Write into database
e: #写入数据库