コード例 #1
0
 def _running_jobs(cls, now, name_match_query):
   return (cls
           ._running_jobs_where(QueueItem.select(QueueItem.queue_name), now)
           .where(QueueItem.queue_name ** name_match_query))
コード例 #2
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
コード例 #3
0
 def _item_by_id_for_update(queue_id):
   return db_for_update(QueueItem.select().where(QueueItem.id == queue_id)).get()
コード例 #4
0
 def get_storage_replication_entry(image_id):
     image = Image.get(docker_image_id=image_id)
     QueueItem.select().where(
         QueueItem.queue_name**("%" + image.storage.uuid + "%")).get()
     return "OK"
コード例 #5
0
ファイル: queue.py プロジェクト: zhangli19817/quay
 def _available_jobs(cls, now, name_match_query):
     return cls._available_jobs_where(QueueItem.select(), now).where(
         QueueItem.queue_name**name_match_query)
コード例 #6
0
def ask_disable_namespace(username, queue_name):
    user = model.user.get_namespace_user(username)
    if user is None:
        raise Exception('Unknown user or organization %s' % username)

    if not user.enabled:
        print "NOTE: Namespace %s is already disabled" % username

    queue_prefix = '%s/%s/%%' % (queue_name, username)
    existing_queue_item_count = (QueueItem.select().where(
        QueueItem.queue_name**queue_prefix).where(
            QueueItem.available == 1, QueueItem.retries_remaining > 0,
            QueueItem.processing_expires > datetime.now()).count())

    repository_trigger_count = (
        RepositoryBuildTrigger.select().join(Repository).where(
            Repository.namespace_user == user).count())

    print "============================================="
    print "For namespace %s" % username
    print "============================================="

    print "User %s has email address %s" % (username, user.email)
    print "User %s has %s queued builds in their namespace" % (
        username, existing_queue_item_count)
    print "User %s has %s build triggers in their namespace" % (
        username, repository_trigger_count)

    confirm_msg = "Would you like to disable this user and delete their triggers and builds? [y/N]> "
    letter = str(raw_input(confirm_msg))
    if letter.lower() != 'y':
        print "Action canceled"
        return

    print "============================================="

    triggers = []
    count_removed = 0
    with db_transaction():
        user.enabled = False
        user.save()

        repositories_query = Repository.select().where(
            Repository.namespace_user == user)
        if len(repositories_query.clone()):
            builds = list(RepositoryBuild.select().where(
                RepositoryBuild.repository << list(repositories_query)))

            triggers = list(RepositoryBuildTrigger.select().where(
                RepositoryBuildTrigger.repository << list(repositories_query)))

            mirrors = list(RepoMirrorConfig.select().where(
                RepoMirrorConfig.repository << list(repositories_query)))

            # Delete all builds for the user's repositories.
            if builds:
                RepositoryBuild.delete().where(
                    RepositoryBuild.id << builds).execute()

            # Delete all build triggers for the user's repositories.
            if triggers:
                RepositoryBuildTrigger.delete().where(
                    RepositoryBuildTrigger.id << triggers).execute()

            # Delete all mirrors for the user's repositories.
            if mirrors:
                RepoMirrorConfig.delete().where(
                    RepoMirrorConfig.id << mirrors).execute()

            # Delete all queue items for the user's namespace.
            dockerfile_build_queue = WorkQueue(queue_name,
                                               tf,
                                               has_namespace=True)
            count_removed = dockerfile_build_queue.delete_namespaced_items(
                user.username)

    info = (user.username, len(triggers), count_removed, len(mirrors))
    print "Namespace %s disabled, %s triggers deleted, %s queued builds removed, %s mirrors deleted" % info
    return user