--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
You might be better off figuring out if you can design your code so that it does not need locking.
You could make it so that whichever client submits processed work from the queue last gets priority.. the other clients work that got returned earlier is just discarded.This way, work could simply be submitted with work entities having explicit key_names and just being .put() to the datastore.Either way, you can easily set up a method so that either, first-submitted or most recently-submitted work is given priority.
Granted I'm not clear on exactly what sort of work is getting processed from your queue. It just seems like you'll expend more resources trying to be exact by not having more than one client grab the same workload.. which will then slow down the apps performance and gobble up more resources.
On Mar 15, 9:28 am, Iap <iap...@gmail.com> 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