Пример #1
0
def sync_replicas(request):
    start_time = time.time()
    part_start_time = time.time()

    master = ReplicaSet.get_what_master()
    try:
        for replica_set in ReplicaSet.objects.all():
            if replica_set.id != master.id:
                trans_sync.sync_all_instances_db(request, replica_set)
        replicas_dbs_time = time.time() - part_start_time
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u"error", u"Error syncing replicas DB: {0}".format(ex), tb)
        return {"success": False, "error": unicode(ex), "traceback": tb}

    try:
        trans_sync.sync_all_replicas_to_master()
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u"error", u"Error running replica sync: {0}".format(ex), tb)
        return {"success": False, "error": unicode(ex), "traceback": tb}
    time_taken = time.time() - start_time

    LogEntry.add(
        request.user,
        u"info",
        u"Completed replica sync in {0:.3f}s. DB in {1:.3f}s.".format(time_taken, replicas_dbs_time),
    )
    return {"success": True}
Пример #2
0
def sync(request):
    start_time = time.time()
    part_start_time = time.time()
    try:
        trans_sync.sync_profile(request)
        profile_time = time.time() - part_start_time
        part_start_time = time.time()
    except Exception as ex:
        profile_time = 0
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error', u'Error syncing profile: {0}'.format(ex), tb)

    try:
        master = ReplicaSet.get_what_master()
        trans_sync.sync_all_instances_db(request, master)
        master_db_time = time.time() - part_start_time
        part_start_time = time.time()
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error', u'Error syncing master DB: {0}({1})'.format(
            type(ex).__name__, ex), tb)
        return {
            'success': False,
            'error': unicode(ex),
            'traceback': tb
        }

    # try:
    # if trans_sync.sync_fulltext():
    # LogEntry.add(request.user, u'error', u'Fulltext table was out of sync. Synced.')
    # except Exception as ex:
    # tb = traceback.format_exc()
    # LogEntry.add(request.user, u'error', u'Error syncing fulltext table: {0}'.format(ex), tb)
    # return {
    # 'success': False,
    # 'error': unicode(ex),
    # 'traceback': tb
    # }

    time_taken = time.time() - start_time
    LogEntry.add(request.user, u'info',
                 u'Completed what.cd sync in {0:.3f}s. Profile in {1:.3f}s. Master DB in {2:.3f}s.'
                 .format(time_taken, profile_time, master_db_time))
    return {
        'success': True
    }
Пример #3
0
def sync(request):
    start_time = time.time()
    part_start_time = time.time()
    try:
        trans_sync.sync_profile(request)
        profile_time = time.time() - part_start_time
        part_start_time = time.time()
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error', u'Error syncing profile: {0}'.format(ex), tb)

    try:
        master = ReplicaSet.get_what_master()
        trans_sync.sync_all_instances_db(request, master)
        master_db_time = time.time() - part_start_time
        part_start_time = time.time()
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error', u'Error syncing master DB: {0}({1})'.format(type(ex).__name__, ex), tb)
        return {
            'success': False,
            'error': unicode(ex),
            'traceback': tb
        }

    # try:
    # if trans_sync.sync_fulltext():
    # LogEntry.add(request.user, u'error', u'Fulltext table was out of sync. Synced.')
    # except Exception as ex:
    # tb = traceback.format_exc()
    # LogEntry.add(request.user, u'error', u'Error syncing fulltext table: {0}'.format(ex), tb)
    #     return {
    #         'success': False,
    #         'error': unicode(ex),
    #         'traceback': tb
    #     }

    time_taken = time.time() - start_time
    LogEntry.add(request.user, u'info',
                 u'Completed what.cd sync in {0:.3f}s. Profile in {1:.3f}s. Master DB in {2:.3f}s.'
                 .format(time_taken, profile_time, master_db_time))
    return {
        'success': True
    }
Пример #4
0
def sync_replicas(request):
    start_time = time.time()
    part_start_time = time.time()

    master = ReplicaSet.get_what_master()
    try:
        for replica_set in ReplicaSet.objects.all():
            if replica_set.id != master.id:
                trans_sync.sync_all_instances_db(request, replica_set)
        replicas_dbs_time = time.time() - part_start_time
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error', u'Error syncing replicas DB: {0}'.format(ex), tb)
        return {
            'success': False,
            'error': unicode(ex),
            'traceback': tb
        }

    try:
        trans_sync.sync_all_replicas_to_master()
    except Exception as ex:
        tb = traceback.format_exc()
        LogEntry.add(request.user, u'error', u'Error running replica sync: {0}'.format(ex), tb)
        return {
            'success': False,
            'error': unicode(ex),
            'traceback': tb
        }
    time_taken = time.time() - start_time

    LogEntry.add(request.user, u'info',
                 u'Completed replica sync in {0:.3f}s. DB in {1:.3f}s.'.format(time_taken,
                                                                               replicas_dbs_time))
    return {
        'success': True
    }