示例#1
0
def check_queue():
    """
    Checks the pending task queue and, given there's not an in-progress task
    for the given APP + ENV, marks the latest as in progress and fires the
    execute_task job.
    """
    pending_queues = list(db.session.query(
        Task.app_id, Task.environment
    ).filter(
        Task.status == TaskStatus.pending
    ).group_by(
        Task.app_id, Task.environment
    ))
    logging.info('Found pending tasks for %d queues', len(pending_queues))

    for app_id, environment in pending_queues:
        app = App.query.get(app_id)
        with lock(redis, 'taskcheck:{}-{}'.format(app.id, environment), timeout=5):
            if has_active_task(app.id, environment):
                logging.info('Task already in progress for %s/%s', app.name, environment)
                continue

            task_id = get_pending_task_id(app.id, environment)
            if not task_id:
                logging.info('Unable to find a pending task for %s/%s', app.name, environment)
                continue

            Task.query.filter(
                Task.id == task_id
            ).update({
                'status': TaskStatus.in_progress,
            }, synchronize_session=False)

            queue.push("freight.jobs.execute_task", [task_id])
示例#2
0
    def delete(self, app):
        """
        Delete an app.
        """
        app = App.query.filter(App.name == app).first()
        if app is None:
            return self.error('Invalid app', name='invalid_resource', status_code=404)

        queue.push('freight.jobs.delete_object', kwargs={'model': 'App', 'app_id': app.id})

        return self.respond({"id": str(app.id)})
示例#3
0
def check_queue():
    """
    Checks the pending task queue and, given there's not an in-progress task
    for the given APP + ENV, marks the latest as in progress and fires the
    execute_task job.
    """
    tasks = list(db.session.query(
        Task.id, Task.app_id
    ).filter(
        Task.status == TaskStatus.pending
    ).group_by(
        Task.id, Task.app_id
    ))

    if not tasks:
        return

    logging.info('Found pending tasks for %d queues', len(tasks))

    deploys = list(db.session.query(
        Deploy.id, Deploy.app_id, Deploy.environment
    ).filter(
        Deploy.task_id.in_(set(t.id for t in tasks))
    ).group_by(
        Deploy.id, Deploy.app_id, Deploy.environment
    ))

    apps = {
        a.id: a
        for a in App.query.filter(
            App.id.in_(set(t.app_id for t in tasks)),
        )
    }

    for deploy_id, app_id, environment in deploys:
        app = apps[app_id]
        with lock(redis, 'deploycheck:{}-{}'.format(app.id, environment), timeout=5):
            if has_active_deploy(app.id, environment):
                logging.info('Deploy already in progress for %s/%s', app.name, environment)
                continue

            task_id = get_pending_task_id(app.id, environment)
            if not task_id:
                logging.info('Unable to find a pending deploy for %s/%s', app.name, environment)
                continue

            Task.query.filter(
                Task.id == task_id
            ).update({
                'status': TaskStatus.in_progress,
            }, synchronize_session=False)

            queue.push("freight.jobs.execute_deploy", [deploy_id])
示例#4
0
def check_queue():
    """
    Checks the pending task queue and, given there's not an in-progress task
    for the given APP + ENV, marks the latest as in progress and fires the
    execute_task job.
    """
    tasks = list(
        db.session.query(Task.id, Task.app_id).filter(
            Task.status == TaskStatus.pending).group_by(Task.id, Task.app_id))

    if not tasks:
        return

    logging.info('Found pending tasks for %d queues', len(tasks))

    deploys = list(
        db.session.query(Deploy.id, Deploy.app_id, Deploy.environment).filter(
            Deploy.task_id.in_(set(t.id for t in tasks))).group_by(
                Deploy.id, Deploy.app_id, Deploy.environment))

    apps = {
        a.id: a
        for a in App.query.filter(App.id.in_(set(t.app_id for t in tasks)), )
    }

    for deploy_id, app_id, environment in deploys:
        app = apps[app_id]
        with lock(redis,
                  'deploycheck:{}-{}'.format(app.id, environment),
                  timeout=5):
            if has_active_deploy(app.id, environment):
                logging.info('Deploy already in progress for %s/%s', app.name,
                             environment)
                continue

            task_id = get_pending_task_id(app.id, environment)
            if not task_id:
                logging.info('Unable to find a pending deploy for %s/%s',
                             app.name, environment)
                continue

            Task.query.filter(Task.id == task_id).update(
                {
                    'status': TaskStatus.in_progress,
                },
                synchronize_session=False)

            queue.push("freight.jobs.execute_deploy", [deploy_id])
示例#5
0
    def delete(self, app):
        """
        Delete an app.
        """
        app = App.query.filter(App.name == app).first()
        if app is None:
            return self.error("Invalid app",
                              name="invalid_resource",
                              status_code=404)

        queue.push("freight.jobs.delete_object",
                   kwargs={
                       "model": "App",
                       "object_id": app.id
                   })

        return self.respond({"id": str(app.id)})