示例#1
0
 def cancel(self, item_id):
     """ Attempts to cancel the queue item with the given ID from the queue. Returns true on success
     and false if the queue item could not be canceled.
 """
     count_removed = QueueItem.delete().where(
         QueueItem.id == item_id).execute()
     return count_removed > 0
示例#2
0
def delete_expired(expiration_threshold, deletion_threshold, batch_size):
    """
  Deletes all queue items that are older than the provided expiration threshold in batches of the
  provided size. If there are less items than the deletion threshold, this method does nothing.

  Returns the number of items deleted.
  """
    to_delete = list(QueueItem.select().where(
        QueueItem.processing_expires <= expiration_threshold).limit(
            batch_size))

    if len(to_delete) < deletion_threshold:
        return 0

    QueueItem.delete().where(QueueItem.id << to_delete).execute()
    return len(to_delete)
示例#3
0
  def delete_namespaced_items(self, namespace, subpath=None):
    """ Deletes all items in this queue that exist under the given namespace. """
    if not self._has_namespaced_items:
      return False

    subpath_query = '%s/' % subpath if subpath else ''
    queue_prefix = '%s/%s/%s%%' % (self._queue_name, namespace, subpath_query)
    return QueueItem.delete().where(QueueItem.queue_name ** queue_prefix).execute()