Tuesday, August 20, 2013

Re: Django Periodic tasks

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlIT01QACgkQuYLL1cDjHx2fYQCeMR2/7Ruw/jCuogDMKYJ86nG9
qScAnj27syp4vvVQnLX1lxkJBkLQVqqd
=GA8x
-----END PGP SIGNATURE-----
On Sat, 17 Aug 2013 03:36:29 +0100 Some Developer
<someukdeveloper@gmail.com> wrote:
> I'm aware of django-cron and django-celery, both of which are capable
> of doing what I want but I was wondering if I was just making a
> fundamental design mistake and there maybe a better option that
> someone here could explain.
>
> Basically customers pay money into their account in advance so that
> they can use services that we offer. Each service is charged by the
> minute and prices between services can vary wildly. I need to be able
> to show our clients their current running total to the nearest hour
> so that they know when they need to add extra funds to their account.
>
> My initial thought was that I would just have the equivalent of a
> cron job running every hour that queries the database for the state
> of each users application and then used that to produce an estimate
> for their current billing.
>
> Alternately I could get rid of the hourly period task and just work
> it out when a customer visits a certain page but that is likely to
> lead to long load times and heavy database use.
>
> Any suggestions on what you would do in this situation?

Calculate the value on each visit for now.
Worry about the execution-time when your database actually has lots of
users, payments and service-charges applied and the site does get slow
to load. Then use django-debug-toolbar to see how many queries your are
running to calculate the number and how long these queries take. Try to
reduce the number of queries, do whatever you can in the database
instead of in python.
When you have reached your end of wisdom while optimizing the
algorithm and the sql (or djangos use of sql through the orm), start
looking into celery/cron/django-extensions. While celery _can_ do
regular jobs, its not really its primary use. And probably not worth
setting up celery+redis when you only want it to do cron-jobs. If you
need celery for other stuff already, then use it for cron-jobs too. But
otherwise its probably better to look at the cronjobs-framework of
django-extensions.

Have fun,

Arnold

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate