Re: Auto-notify outside/API services when instance Updated - Best Practices?

2008-11-21 Thread Rajesh Dhawan



On Nov 20, 3:40 pm, "John.R" <[EMAIL PROTECTED]> wrote:
> I'm working with an Event Model that, when saved (and possibly when
> updated) needs to run some custom Python code to notify some outside
> APIs - Twitter, Pownce, Google Calendar for instance.
>
> I know enough to implement Signals so that I don't have to code
> anything into the Event model itself if we change or add APIs later -
> but what's the best approach to this, when handling things like:
>
> What if one of several APIs is unavailable for update?
> Best way to keep track of that, and update only the correct ones
> later?
>
> -
> My initial thinking is to create a related Model that will store
> information in properties, like "was_twittered",
> "x_service_was_notified" that has a OneToOne relationship with the
> Event Model. Then in Signals I would create a new instance of that,
> related to the Event being saved/updated, and call a method on it that
> would attempt to contact any services that don't have their related
> "x_was_notified" property set to True.
>
> But then, what about later? What if one doesn't respond? How do I go
> back and tell it to retry later? Use cron? Implement a Django-based
> cron app? I'd like to self-contain as much as possible with this, so
> as to Not Repeat Myself, and to not go one a "wild goose chase" if
> something acts buggy later.
>
> Any ideas?

You could write messages to a queue model and set up a cron job that
picks up and dispatches "unprocessed" messages every X minutes. If the
cron job manages to process a message successfully, it marks that
message as "processed" or removes it from the queue. The messages
could be in a simple-to-parse format like JSON. This way, you can use
this mechanism for different kinds of events and activities without
tying it to one model.

Take a look at the Django Queue Service for a start:
http://code.google.com/p/django-queue-service/
For Django 1.0 compatibility, you will need to pick up the latest
branch from here: 
http://django-queue-service.googlecode.com/svn/branches/unstable/

-Rajesh D
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Auto-notify outside/API services when instance Updated - Best Practices?

2008-11-20 Thread John.R

I'm working with an Event Model that, when saved (and possibly when
updated) needs to run some custom Python code to notify some outside
APIs - Twitter, Pownce, Google Calendar for instance.

I know enough to implement Signals so that I don't have to code
anything into the Event model itself if we change or add APIs later -
but what's the best approach to this, when handling things like:

What if one of several APIs is unavailable for update?
Best way to keep track of that, and update only the correct ones
later?

-
My initial thinking is to create a related Model that will store
information in properties, like "was_twittered",
"x_service_was_notified" that has a OneToOne relationship with the
Event Model. Then in Signals I would create a new instance of that,
related to the Event being saved/updated, and call a method on it that
would attempt to contact any services that don't have their related
"x_was_notified" property set to True.

But then, what about later? What if one doesn't respond? How do I go
back and tell it to retry later? Use cron? Implement a Django-based
cron app? I'd like to self-contain as much as possible with this, so
as to Not Repeat Myself, and to not go one a "wild goose chase" if
something acts buggy later.

Any ideas?

Thanks!

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---