Python Forum
Managing recursive tasks in celery.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Managing recursive tasks in celery.
#1
I have a number of tasks that I want to chain to build a pipeline. It consists of two main tasks, fetch_data and post_process. The fetch_data task is a recursive task. What I want is to have all the fetch_data tasks to complete before post_process is run.

However, the post_processing seems to run after the first task is completed. How do i make the post processing run after all the fetch tasks are completed?
@shared_task
def multi_fetch(count):
    fetch_id = uuid.uuid4()
    if count > 0:
        multi_fetch.delay(count - 1)
    print(f"Fetching data....[{fetch_id}]")
    time.sleep(random.randint(5, 15))
    return fetch_id


@shared_task
def multi_post_process(fetch_id):
    print(f"Post processing...[{fetch_id}]")


workflow = chain(fetch_data.s(5), multi_post_process.s())
workflow.run()
Reply
#2
Looking at the celery documentation, I think you want to use a group for multi_fetch (just fetch now since group will do the multi) to run multiple tasks at the same time and wait for them to all finish.
workflow = group(fetch.s(i) for i in range(6))
To chain the group with your post process.
workflow = (group(fetch.s(i) for i in range(6)) | multi_post_process.s())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to process tasks as they complete when using TaskGroup? odigity 2 868 Sep-17-2024, 03:42 PM
Last Post: odigity
  Multiprocessing Managing Help m7md_hka 0 384 Aug-22-2024, 09:57 AM
Last Post: m7md_hka
  drawing a table with the status of tasks in each thread pyfoo 3 1,306 Mar-01-2024, 09:29 AM
Last Post: nerdyaks
  managing new windows JonWayn 1 2,616 Sep-22-2022, 05:26 PM
Last Post: Larz60+
  How to script repetitive tasks in dynaform using python BenneGrus 0 1,910 Dec-22-2021, 08:36 AM
Last Post: BenneGrus
  Managing Objects JoeDainton123 1 2,224 May-15-2021, 03:18 PM
Last Post: Yoriz
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 10,004 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  asyncio: executing tasks + httpserver freebsdd 2 3,463 Aug-29-2020, 09:50 PM
Last Post: freebsdd
  Managing dependencies with pipenv t4keheart 6 4,331 Aug-05-2020, 12:39 AM
Last Post: t4keheart
  managing command codes for external controller box Oolongtea 0 2,307 Sep-19-2019, 08:32 AM
Last Post: Oolongtea

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020