On Mar 15, 9:28 am, Iap <[email protected]> wrote:
>
> The other suggestion is the "transaction". I encountered many exceptions
> while putting the step 3.2, 3.3 to a transaction.
> Such as "nested transaction is not allowed","Cannot operate on different
> entity groups","must be an ancestor...".
> Because the transaction has so much limitation, it seems not realistic to
> use transaction.


Something like this?



class Queued(db.Model):
    done = db.BooleanProprty(required=True, default=False)
    order = db.DateTimeProperty(required=True, auto_now_add=True)

    work = db.TextProperty() # whatever...

    @classmethod
    def get_next(cls):
        next = None
        while next is None:
            next = cls.all().filter('done =', False) \
                      .order('order').fetch(1)
            if next is None:
                return None
            next = cls._mark_done_transactionally(next)
        return next

    @classmethod
    def _mark_done_transactionally(cls, queued):
        def txn(queued):
            queued = db.Get(queued.key())
            if queued.done:
                return None
            queued.done = True
            queued.put()
            return queued
        return db.run_in_transaction(txn, queued)


some_work_to_do = Queued.get_next()
if some_work_to_do:
    print 'Do once: %s' % some_work_to_do.work

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to