I was thinking of creating a cron job and a python script, but I would
rather have the process be part of my django application so I don't
have to worry about extra stuff.
Another thought was to use a time, but if the timer process stops
before the message is sent, that's it KABAAAAAMMMMM.
Any thoughts on how to handle this situation? Thanks.
Scott
--
Scott A. Macri
www.ScottMacri.com
(571) 234-1581
> I'm trying to figure out the best way to create an automated in a
> python/django web application. My intention is to send an email
> message in the future based on the given future date/time. What is
> the best approach to do this?
>
> I was thinking of creating a cron job and a python script, but I would
> rather have the process be part of my django application so I don't
> have to worry about extra stuff.
If you want to have the active code in Django, you could run a cron to call wget or similar to call a specific URL that does whatever. If you choose to do this, make sure it is locked down - perhaps only execute if REMOTE_HOST is 127.0.0.1.
I generally don't recommend this approach, because it really is mixing distinct functions. What happens if you grow to multiple servers? What happens if you're sending enough mail that you split that off to its own cluster?
Note that it should be straightforward to pull in the Django template classes, if you want to use that for generating your messages.
Also, note that this is precisely what cron is for. Attempting to recreate cron inside of a web application is going to end in tears. Keep your cron job and support scripts in a separate directory in your source repository, and add a checklist for setting it up to your documentation (which is also versioned, right?).
My .02 units of your currency,
-j
> I'm trying to figure out the best way to create an automated in a
> python/django web application. My intention is to send an email
> message in the future based on the given future date/time. What is
> the best approach to do this?
>
> I was thinking of creating a cron job and a python script, but I would
> rather have the process be part of my django application so I don't
> have to worry about extra stuff.
...
> Any thoughts on how to handle this situation? Thanks.
Yeah - use a cron job and a Python script :-)
Seriously -- Django is good at what it does, but just because you've got a really good hammer, it doesn't mean every problem is a nail. The task you describe sounds like almost exactly what cron scripts are designed to handle. Rather than trying to bend Django into a shape that will solve your problem, use the right tool for the job.
You might also be able to attack the problem using a task queue like celery [1]. However, celery is more complex to get set up than a cron script. There are lots of benefits that come with that complexity, but if you just want to get something going, you don't have any experience with task queues, and you're not expecting any serious load problems, cron will be the easier option.
It's also worth pointing out that you can still use parts of Django (e.g., your models, the ORM, the mail sending utilities) in a standalone Python script that is called by cron/celery. Django is a just a set of Python libraries. Yes, it's a set of libraries that is usually used to build web sites, and most examples use Django APIs to service HTTP requests, but there's no reason you can't write a standalone Python script that uses Django's APIs to access and manipulate data.
Yours,
Russ Magee %-)
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Seriously -- Django is good at what it does, but just because you've got a really good hammer, it doesn't mean every problem is a nail. The task you describe sounds like almost exactly what cron scripts are designed to handle. Rather than trying to bend Django into a shape that will solve your problem, use the right tool for the job.You might also be able to attack the problem using a task queue like celery [1]. However, celery is more complex to get set up than a cron script. There are lots of benefits that come with that complexity, but if you just want to get something going, you don't have any experience with task queues, and you're not expecting any serious load problems, cron will be the easier option.
It's also worth pointing out that you can still use parts of Django (e.g., your models, the ORM, the mail sending utilities) in a standalone Python script that is called by cron/celery. Django is a just a set of Python libraries. Yes, it's a set of libraries that is usually used to build web sites, and most examples use Django APIs to service HTTP requests, but there's no reason you can't write a standalone Python script that uses Django's APIs to access and manipulate data.