Can always-on tasks "listen" to a db continuously without taking up CPU time?

I want to offload some heavy calculation processes from my Django web app, and thought that always-on tasks might be the way to go in PythonAnywhere (since Celery is unsupported).

I imagine the process would be like this:

  1. A user sends a "Calculate" request from the Django web interface
  2. The web app updates a DB value
  3. The always-on task picks up the DB's value signalling to do some calculation, and takes up CPU time
  4. After calculation, the always-on task returns back to normal mode without burning CPU time

Can this be done? Or perhaps there is a better way to do this in PythonAnywhere, like maybe use a different way to listen to those "calculation begin" signals?

Hey, yeah thats the way we'd recommend to do things -

@sboyd But how do I know for sure what activity will take up CPU time, what won’t?

Is there a specific function to be used so that it can “listen” to a db but not take up CPU time?

The only way I know is like to set an infinite loop for example iterating every 10 seconds, and then check if the db status has changed.

This will take CPU time indefinitely wouldn’t it?

You have to tune to balance between how often it is doing something and how much CPU you have.