Hacker News new | ask | show | jobs
by jholloway7 2363 days ago
Not sure if lower-level API of RQ supports this, but I tend to prefer message-oriented jobs that don't couple the web app to the task handler like the example.

I don't want to import "count_words_at_url" just to make it a "job" because that couples my web app runtime to whatever the job module needs to import even though the web app runtime doesn't care how the job is handled.

I want to send a message "count-words" with the URL in the body of the message and let a worker pick that up off the queue and handle it however it decides without the web app needing any knowledge of the implementation. The web app and worker app can have completely different runtime environments that evolve/scale independently.

2 comments

Agreed - which is why I don't put my business logic in the webapp, or use models coupled to the web framework.

The web framework is a way to handle http, rest, or graphql - deserializing and serializing those protocols, not a way to handle my business logic.

Decoupling these things lets you write one-off scripts or have task queues that don't need to load the context of a large web framework - they can just be simple python.

Docs say you can pass a string instead of a function.