TacoQ Logo
Guides

Same-app Worker

Set up a worker and publisher in the same application to make your life easier.

Motivation

During development and testing, it might be too much of a hassle to run a separate process just for your worker. Thankfully, the worker's lifecycle is asynchronous and can run alongside the rest of your application.

Implementation

You can set up the worker to run along with the rest of your application by running it in the background in an idiomatic way:

# Set up your application as normal
worker_app = WorkerApplication(...)

# Instead of running the worker app via the CLI or a dedicated
# entrypoint, run it the background as a co-routine.
asyncio.create_task(worker_app.entrypoint())

# When you are done using your worker, you can stop it
# by calling the shutdown method.
worker_app.shutdown()

# If you want to wait for the worker to finish cleaning up the remaining
# tasks, you can await the `wait_for_shutdown` method.
await worker_app.wait_for_shutdown()

This pattern is not recommended for production use because: - It is important to separate the resources used by your worker and your application.

  • You cannot horizontally scale your worker by running multiple instances. - Your worker may have blocking tasks that will interfere with your application's performance. If you are using an asynchronous runtime like tokio, the impact of blocking tasks may not be as pronounced due to the multiple threads available. In asyncio, however, a blocking task in your worker will block the entire process.
TacoDivision Logo

Frameworks

TacoQ

TacoDocs

WIP

TacoFlow

Soon

TacoBI

Soon

TacoCI

Soon

Taco Plus

Docs Templates

WIP

Early Access

Soon

Priority Support

Soon

BI Templates

Soon

Community

© 2025 Taco Division.
All rights reserved.