

def _execute(self, params):
    (generated_sql, query_params) = self._generate_sql(params)
    rows = self._db_query(('\n            SELECT\n                id,\n                created,\n                last_contact,\n                spec,\n                IFNULL(tasks_total, 0)                                          AS tasks_total,\n                IFNULL(tasks_cancelled, 0)                                      AS tasks_cancelled,\n                IFNULL(tasks_errored, 0)                                        AS tasks_errored,\n                IFNULL(tasks_queued, 0)                                         AS tasks_queued,\n                -- Tasks that are cancelled count as finished also\n                -- It is always true that if one is null, all are null\n                IFNULL(tasks_total - tasks_queued - tasks_finished, 0)          AS tasks_running,\n                IFNULL(tasks_finished, 0)                                       AS tasks_finished,\n                %(state_projection)s                                            AS state,\n                bytes_total,\n                bytes_downloaded,\n                download_rate,\n                first_task_start\n            FROM\n                jobs\n                LEFT JOIN(\n                    SELECT\n                        tasks.job_id,\n\n                        MIN(tasks.started)                                      AS first_task_start,\n                        MAX(tasks.last_contact)                                 AS last_contact,\n\n                        -- counts\n                        -- These casts are necessary because MemSQL makes arbitrary choices\n                        COUNT(tasks.id)                                         AS tasks_total,\n                        CAST(SUM(%(cancelled_cond)s) AS SIGNED)                 AS tasks_cancelled,\n                        CAST(SUM(%(error_cond)s) AS SIGNED)                     AS tasks_errored,\n                        CAST(SUM(%(finished_cond)s) AS SIGNED)                  AS tasks_finished,\n                        CAST(SUM(%(queued_cond)s) AS SIGNED)                    AS tasks_queued,\n\n                        -- download information\n                        -- CAST because JSON number types are always floats\n                        CAST(SUM(tasks.bytes_total) AS SIGNED)        AS bytes_total,\n                        CAST(SUM(tasks.bytes_downloaded) AS SIGNED)   AS bytes_downloaded,\n                        CAST(SUM(tasks.download_rate) AS SIGNED)      AS download_rate\n                    FROM tasks\n                    GROUP BY tasks.job_id\n                ) AS job_tasks ON job_tasks.job_id = jobs.id\n            %(where_expr)s\n            ORDER BY %(order_by)s %(order)s\n            %(paging)s\n        ' % generated_sql), **query_params)
    for row in rows:
        time_left = (- 1)
        no_nulls = (None not in (row.last_contact, row.first_task_start, row.bytes_downloaded))
        if ((row.state == shared.JobState.RUNNING) and no_nulls and (row.bytes_downloaded != 0)):
            last_contact = dateutil.parser.parse(row.last_contact)
            first_task_start = dateutil.parser.parse(row.first_task_start)
            time_since_start = (last_contact - first_task_start)
            overall_download_rate = (params.bytes_downloaded / max(time_since_start.total_seconds(), 1))
            bytes_remaining = (row.bytes_total - row.bytes_downloaded)
            if (overall_download_rate > 0):
                time_left = (bytes_remaining / overall_download_rate)
        row['time_left'] = time_left
    return [shared.job_load_row(row) for row in rows]

dataset/ETHPy150Open memsql/memsql-loader/memsql_loader/api/jobs.py Jobs._execute/VarMisuse@140/932 `row`->`params`