Platform 04 · Study guide
Move slow work off the request thread with sync, database, or Redis queue drivers.
from tpy.queue import Job, Queue, SyncQueueDriver
class SendWelcomeEmail(Job):
def __init__(self, user_id: str) -> None:
self.user_id = user_id
def handle(self) -> None:
# send email here
print("welcome", self.user_id)
# Development: run inline in the same process
Queue(SyncQueueDriver()).push(SendWelcomeEmail("u1"))
$ tpy queue table $ tpy queue work --driver database --once $ tpy queue work --driver database
queue table creates _tpy_jobs (and failed-job storage). Workers pull jobs and call handle().
$ pip install "tamilPY[redis]" $ tpy queue work --driver redis --redis-url redis://localhost:6379/0
push()es a Job instance onto a Queue.handle().SyncQueueDriver in tests. Use database/redis workers in real deployments so HTTP requests stay fast.