Skip to content

Building an app featuring multiple tasks

Let's recap, in the previous section, we learnt how to:

  • transform Python functions into asynchronous tasks
  • register tasks with a name
  • create tasks with arguments
  • create task which can publish progress updates

Full async app

If we put everything together, we can build a full async app, featuring multiple tasks:

my_app.py
from icij_worker import AsyncApp
from icij_worker.typing_ import RateProgress

app = AsyncApp("some-app")


@app.task(name="hello_world")
def hello_world() -> str:
    return "Hello world"


@app.task(name="hello_user")
def hello_user(user: str | None) -> str:
    greeting = "Hello "
    if user is None:
        user = "unknown"
    return greeting + user


@app.task(name="hello_user_progress")
async def hello_user_progress(user: str | None, progress: RateProgress) -> str:
    greeting = "Hello "
    await progress(0.5)
    if user is None:
        user = "unknown"
    res = greeting + user
    await progress(1)
    return res

Next

Perfect, we've built our first app by registering many async tasks, we need to run pool of async workers to execute these task when asked to do so !