python 2.7 - Django-Execute function after Celery job completion -


i using celery fabric. celery task copying file local machine this:

@app.task def copytolocal():  get('/home/remote/file.txt','/home/local/') # copying local dir 

when in view try open , read file ioerror because task not completed yet

taskfile.app.send_task('taskfile.copytolocal',[]) # sending task queue open('/home/local/file.txt') #ioerror because task isnt completed yet            

if use asyncresult.ready() returning false @ execution momement. there way implement callback or else , how it.

the easy way

while not asyncresult.ready():     time.sleep(1)  # file downloaded 

and if want bit nicer can use callbacks link task performed when regular task done.

download_file.apply_async(path, link=write_to_db.subtask(path)) 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -