On Jun 25, 12:54 am, Wiiboy <jordon...@gmail.com> wrote:
> I'm a bit of a noob at Web Devlopment (as you already know if you've
> read any of my posts on here).
>
> I've read that using hooks in key places in a website can help ease
> future development. Can/Should Django's signals be used for that
> purpose?
>
> If so, to what extent should they be used? For example, on my site
> where users submit articles for a newsletter, one place to put a hook
> would be after an article is submitted. Would sending emails to
> admins about the new submission, as well as emails to the users who
> subscribe to be notified of new submissions be put in a separate
> function, as part of the hook, or part of the page?
This really depends on how many users have subscribed. If it's in the
thousands then sending an email inline (be it via signal hooks or
directly in a view or in a model.save) is going to cause some problems
to the user who just submitted an article; that user will now have to
wait for the entire emailing loop to complete before his/her request
completes. So if you have scalability concerns like this, you might
want to look at an offline-messaging-based architecture where a signal
hook writes out a special message to a work queue, an offline/cron
scheduled job periodically reads from the work queue and gets the
heavy weight lifting done without bogging down your HTTP requests.
Going back to your original question, signals are a great way to hook
in event driven functionality into your apps. It allows you to keep
your event processing code separate from your models, forms, or views.
That's usually a good thing. Signals also allow you to add processing
to a third-party django app without modifying the app's code.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---