How do you return the result of a completed celery task and store the data in variables?


I have two flask modules and

I set up Celery in to complete a selenium webdriver request (which takes about 20 seconds). My goal is to simply return the result of that request to

Running the Celery worker on another terminal, I can see in the console that the Celery task completes successfully and prints all the data I need from the selenium request. However, now I just want to return the task result to

How do I obtain the celery worker results data from and store each result element as a variable in

I define the marketplace and call the task function and request the indexed results:

import tasks

marketplace = 'cheddar_block_games'

# This is what I am trying to get back:
price_check = tasks.scope(marketplace[0])
image = tasks.scope(marketplace[1])

celery = Celery(broker='redis://')

 def scope(marketplace):
     price_check = WebDriverWait(web,30).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[2]/div[2]/div[3]/div[2]/div[2]/div[3]/div[2]/div[4]/div/div[2]/div[1]/div[2]/div/div[2]/div/div[2]/div/span/div[2]/div/span[1]"))).text
     image = WebDriverWait(web,30).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[2]/div[2]/div[3]/div[2]/div[2]/div[3]/div[2]/div[4]/div/div[2]/div[1]/div[2]/div/div[1]/div/div/img")))

     return (price_check, image)


This answer might be relevant: should call the task e.g. using scope.delay or scope.apply_async. You could then fetch the task result with AsyncResult.get():

Since the task returns a tuple, you can store each variable by unpacking it:

The result would be something like this:

import tasks

marketplace = 'cheddar_block_games'

result = tasks.scope.delay(marketplace)
price_check, image = result.get()

Answered By – luisgc93

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published