Esempio n. 1
0
    def _execute(self, params):
        generated_sql, query_params = self._generate_sql(params)

        job_count = self._db_get('''
            SELECT COUNT(*) AS count
            FROM jobs
            WHERE %(job_id_predicate)s
        ''' % generated_sql, **query_params).count

        if job_count == 0:
            raise exceptions.ApiException('No job found with id `%s`' % params['job_id'])
        elif job_count > 1:
            raise exceptions.ApiException('More than one job matches id `%s`, try using a more specific prefix' % params['job_id'])

        rows = self._db_query('''
            SELECT
                tasks.*,
                %(state_projection)s AS state
            FROM tasks INNER JOIN jobs ON jobs.id = tasks.job_id
            WHERE
                %(job_id_predicate)s
                %(state_predicate)s
            ORDER BY %(order_by)s %(order)s
            %(paging)s
        ''' % generated_sql, **query_params)

        ret = []
        for row in rows:
            row = shared.task_load_row(row)
            row['key_name'] = row.data['key_name']
            row['error_msg'] = row.data.get('error') or ''
            ret.append(row)
        return ret
Esempio n. 2
0
    def _execute(self, params):
        generated_sql, query_params = self._generate_sql(params)

        task_row = self._db_get('''
            SELECT *, %(state_projection)s AS state
            FROM tasks
            WHERE
                %(task_id_predicate)s
            LIMIT 1
        ''' % generated_sql, **query_params)

        if not task_row:
            raise exceptions.ApiException('No task found with id `%s`' % params['task_id'])

        return shared.task_load_row(task_row)