def fetch_or_create_queue(user):
    # Fetch or create the queue
    name = 'oc_queue'
    queues = list(QueueModel().find(name=name, user=user))
    if len(queues) > 0:
        queue = queues[0]
    else:
        type = QueueType.FIFO
        queue = QueueModel().create(name, type_=type, max_running=5, user=user)

    return queue
Exemplo n.º 2
0
    def pop_task(self, queue, multi):
        if multi:
            limit = sys.maxsize
        else:
            limit = 1

        queue = QueueModel().pop(queue, limit, user=self.getCurrentUser())

        return queue
Exemplo n.º 3
0
    def set_max_running(self, queue, maxRunning):
        if maxRunning < 0:
            raise RestException(
                'Invalid maxRunning parameter. maxRunning must be >= 0')

        updates = {'maxRunning': maxRunning}

        queue = QueueModel().apply_updates(queue, updates,
                                           self.getCurrentUser())
        return queue
def launch_taskflow(user, body):
    # Perform some validation
    taskFlowBody = body.get('taskFlowBody')
    if taskFlowBody is None:
        raise RestException('taskFlowBody is a required key')

    if 'taskFlowClass' not in taskFlowBody:
        raise RestException('taskFlowClass is required in taskFlowBody')

    taskflow_class = taskFlowBody['taskFlowClass']

    # Check that we can load the taskflow class
    try:
        load_class(taskflow_class)
    except Exception as ex:
        msg = 'Unable to load taskflow class: %s (%s)' % \
              (taskflow_class, ex)
        raise RestException(msg, 400)

    # Set up the taskflow input
    taskFlowInput = body.get('taskFlowInput', {})
    if 'cluster' not in taskFlowInput:
        # Make a cluster
        taskFlowInput['cluster'] = create_cluster_object(user)

    if 'container' not in taskFlowInput:
        taskFlowInput['container'] = 'docker'

    # Load the queue
    queue = fetch_or_create_queue(user)

    # Create the taskflow
    taskflow = TaskflowModel().create(user, taskFlowBody)

    # Add it to the queue and start it
    QueueModel().add(queue, taskflow, taskFlowInput, user)
    QueueModel().pop(queue, limit=sys.maxsize, user=user)

    return taskflow['_id']
Exemplo n.º 5
0
    def create(self, name, type, maxRunning):
        if type is None or type.lower() not in QueueType.TYPES:
            type = QueueType.FIFO

        if maxRunning < 0:
            raise RestException(
                'Invalid maxRunning parameter. maxRunning must be >= 0')

        queue = QueueModel().create(name,
                                    type_=type,
                                    max_running=maxRunning,
                                    user=self.getCurrentUser())
        cherrypy.response.status = 201
        return queue
Exemplo n.º 6
0
 def remove(self, queue):
     QueueModel().remove(queue)
     cherrypy.response.status = 204
     return
Exemplo n.º 7
0
 def find(self, name):
     return list(QueueModel().find(name=name, user=self.getCurrentUser()))
Exemplo n.º 8
0
 def add_task(self, queue, taskflow, body):
     queue = QueueModel().add(queue, taskflow, body, self.getCurrentUser())
     return queue