Esempio n. 1
0
def get_osc_percent(task_id):
    """实时获取pt-online-schema-change执行进度"""
    task = AsyncResult(task_id)

    while task.state in ('PENDING', 'STARTED', 'PROGRESS'):
        while task.state == 'PROGRESS':
            user = task.result.get('user')
            host = task.result.get('host')
            port = task.result.get('port')
            database = task.result.get('database')
            sqlsha1 = task.result.get('sqlsha1')

            sql = f"inception get osc_percent '{sqlsha1}'"
            of_audit = InceptionSqlApi(host, port, database, sql, user)

            # 执行SQL
            of_audit.run_status(1)

            # 每1s获取一次
            time.sleep(1)
        else:
            continue
Esempio n. 2
0
def stop_incep_osc(user, id=None, celery_task_id=None):
    obj = SqlOrdersExecTasks.objects.get(id=id)
    host = obj.dst_host
    port = obj.dst_port
    database = obj.dst_database

    exec_status = None
    if obj.exec_status == '2':
        sqlsha1 = obj.sqlsha1
        exec_status = 0
    elif obj.exec_status == '3':
        sqlsha1 = obj.rollback_sqlsha1
        exec_status = 1

    sql = f"inception stop alter '{sqlsha1}'"

    # 执行SQL
    task = AsyncResult(celery_task_id)
    if task.state == 'PROGRESS':
        of_audit = InceptionSqlApi(host, port, database, sql, user)
        of_audit.run_status(0)

        # 更新任务进度
        update_tasks_status(id=id, exec_status=exec_status)