views:

214

answers:

1

Im writing a twitter app in Google App Engine. It accepts commands as Direct Messages, so i have setup a third party cronjob service to invoke a handler that processes DMs at regular intervals. I have a Model 'Info' that has just one entry, it stores some common data which are used in many places in the App(in this case, the time when the messages were processed recently). The general pattern of my handler is like this:

class Info(db.Model):
    msg_polled = db.DateTimeProperty(auto_now_add = True)
    .... More Properties ....

    @classmethod
    def get_info(cls):
        info = cls.all().get()
        if not info:
            info = cls()
            info.put()
        return info
---------------------------------------------------------
info = Info.get_info()
msgs = api.GetDirectMessages(since = info.msg_polled)
if not msgs:
    return
logging.info('Processing Messages since %s ' % str(info.msg_polled))
for msg in msgs:

    ...process commands...

    logging.info('Processed Message :- @%s : %s' % (msg.sender_screen_name, msg.text))

info.msg_polled = datetime.datetime.now()
info.put()

But sometimes i get logs like this :

I 03-30 07:50AM 10.973
Processing Messages since Sun, 29 Mar 2009 11:41:59 GMT 
I 03-30 07:50AM 11.122
Processed Message :- @foo : Foo_Bar
-------------------------------------------------------
I 03-30 07:46AM 08.014
Processing Messages since Sun, 29 Mar 2009 11:41:59 GMT 
I 03-30 07:46AM 08.130
Processed Message :- @foo : Foo_Bar

Here, it seems that info is not getting commited to the database. The message is processed multiple number of times, sometimes upto 10+ times before the msg_polled value changes. But i am not getting any Datastore exceptions. This happens only once in a while.

Any help is appreciated.

A: 

The Google AppEngine datastore uses BigTable under the covers, which is a distributed database system. Because of this, updates might not be visible immediately since the new data has not yet reached every distributed table (Amazon calls this "eventual consistency" in their SimpleDB). You should be fine after a few minutes.

Rik
But the docs have no mention of any such latency.. So, will reducing the frequency of the cronjob solve the problem?
z33m
I know, I searched for some links to support my story, but could find any. I'm sure I've read it somewhere, though.Reducing the frequency could help, indeed. I suggest you give it a shot and see what happens. Let me know!
Rik
The cronjob is currently running once every 4min.. you can see this in the log time stamps.. dont you think 4min is a bit too long for that kind of a delay, even SimpleDB 'eventual consistency' delays are in the order of seconds right?
z33m
4 minutes does sound a bit steep. Wouldn't know what else it could be.. sorry.
Rik
Don't use app-engine.
mP