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

1 view
Skip to first unread message

John.R

unread,
Nov 20, 2008, 3:40:21 PM11/20/08
to Django users
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!

Rajesh Dhawan

unread,
Nov 21, 2008, 1:06:48 PM11/21/08
to Django users
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
Reply all
Reply to author
Forward
0 new messages