Forums

Continuous Database Calls

Hi there,

Just wondering if there is a more efficient way of doing this, I want a process to happen almost instantly, after a user submits something I need to call it from the database, now following the advice here https://www.pythonanywhere.com/forums/topic/1563/ that is fine with a 'roll-your-own' solution as I can keep this going none stop, checking say every 30 seconds but this will eat away at my CPU allowance very quickly, especially as I might not have a user submit something for a few days.

The reason I want it to happen so quickly, is because I need to parse a file to do a number count so I can then do the appropriate billing, i.e. allowance.

Would there be a better way that is more efficient on my CPU? This process generally takes less then a second to do but there will be times where it will take up to 2+ minutes - hence the reason I can just do it between submission page loads.

Thanks in advance.

Ajax?

What would this just pass a command in to run the program as if it were off the console or something? I appreciate this is beyond your support but a nudge in the right direction would be appreciated.

Thanks

Sorry that was a bit monosyllabic!

And actually, now that I read your post more closely, Ajax won't work anyway -- we disconnect any requests that take longer than 120 seconds, whether they're normal button submits or ajax requests.

So the only real solution is a scheduled task. Don't worry about your CPU allowance, something that polls every 30 seconds really won't use up that much allowance, as long as it does a time.sleep() in between polls. Even polling every 10 seconds would be fine, I suspect.

Hey Harry,

Yea, I've had two going for the last two hours what at 20 seconds and one at 5 minutes and it's only used 0.27s of allowance so yea that's fine.

Thanks for your feedback :)

:)