Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generally, you shouldn't try and override the <strong>init</strong> method of Model classes. While it's possible to get right, the correct constructor behaviour is fairly complex, and may even change between releases, breaking your code (though we try to avoid doing so!). Part of the reason for this is that the constructor has to be used both by your own code, to construct new models, and by the framework, to reconstitute models loaded from the datastore.</p> <p>A better approach is to use a factory method, which you call instead of the constructor.</p> <p>Also, you probably want to add the task at the same time as you write the entity, rather than at creation time. If you don't, you end up with a race condition: the task may execute before you've stored the new entity to the datastore!</p> <p>Here's a suggested refactoring:</p> <pre><code>class DeleteQueueItem(db.Model): """Model to keep track of items that will be deleted via task queue.""" # URL path to the blog post is handled as key_name delete_when = db.DateTimeProperty() @classmethod def new(cls, key_name): delay = 120 # Seconds t = datetime.timedelta(seconds=delay) deadline = datetime.datetime.now() - t return cls(key_name=key_name, delete_when=deadline) def put(self, **kwargs): def _tx(): taskqueue.add(url='/admin/task/delete_page', countdown=delay, params={'path': key_name}, transactional=True) return super(DeleteQueueItem, self).put(**kwargs) if not self.is_saved(): return db.run_in_transaction(_tx) else: return super(DeleteQueueItem, self).put(**kwargs) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload