示例#1
0
def fnUpdateRows(cur):
    global lock

    vSTATUS = ''
    vGW_RESP = ''
    vIDs = ''

    for i in range(50):  #atualiza 50 linhas no banco por vez
        try:
            r = QueueUpdate.get_nowait()

            id = r[0]
            status = r[1]
            gw_resp = r[2]

            if (status != -10):
                vSTATUS = vSTATUS + "when id = " + str(id) + " then " + str(
                    status) + " "
                vGW_RESP = vGW_RESP + "when id = " + str(
                    id) + " then '" + gw_resp + "' "
                vIDs = vIDs + str(id) + ","

            QueueUpdate.task_done()

            libextra.fnQueueControl(lock, -1)
        except Exception as e:
            break

    if vIDs == '':
        return (False)

    sql =   " UPDATE MessageQueue" \
            " SET dup = now(), status = case " \
            " "+vSTATUS+" " \
            "     end, " \
            "     gw_resp = case " \
            " "+vGW_RESP+" " \
            "     end " \
            " WHERE status in (0,15) and id in ("+vIDs+"0)"

    while True:
        try:
            #print(sql)
            cur.execute(sql)

            return (True)

        except Exception as e:
            logg.error('Loop4Ever Exception (MySQL conn problem) -> ',
                       exc_info=True)

            cur = libextra.fnMySQLConnect()
            time.sleep(5)
示例#2
0
def fnUpdateRows(cur):
    global lock

    vSTATUS  = ''
    vGW_RESP = ''
    vIDs     = ''

    for i in range(50): #atualiza 50 linhas no banco por vez
        try:
            r = QueueUpdate.get_nowait()


            id      = r[0]
            status  = r[1]
            gw_resp = r[2]

            if (status != -10):
                vSTATUS  = vSTATUS  + "when id = "+str(id)+" then "+str(status)+" "
                vGW_RESP = vGW_RESP + "when id = "+str(id)+" then '"+gw_resp+"' "
                vIDs     = vIDs     + str(id)+","

            QueueUpdate.task_done()

            libextra.fnQueueControl(lock, -1)
        except Exception as e:
            break

    if vIDs == '':
        return(False)

    sql =   " UPDATE MessageQueue" \
            " SET dup = now(), status = case " \
            " "+vSTATUS+" " \
            "     end, " \
            "     gw_resp = case " \
            " "+vGW_RESP+" " \
            "     end " \
            " WHERE status in (0,15) and id in ("+vIDs+"0)"

    while True:
        try:
            #print(sql)
            cur.execute(sql)

            return(True)

        except Exception as e:
            logg.error('Loop4Ever Exception (MySQL conn problem) -> ', exc_info=True)

            cur = libextra.fnMySQLConnect()
            time.sleep(5)
示例#3
0
#
# GLOBAL VARIABLES
#
cSQL_LIMIT   = 20000
cTHREADS_CNT = 200

#
# FIRST STEPS
#
logg.info('************** STARTING DRIVER **************** (Threads: %s)(SQL Limit: %s)',cTHREADS_CNT,cSQL_LIMIT)

QueueMaster = queue.Queue()
QueueUpdate = queue.Queue()
lock = threading.Lock()

cur = libextra.fnMySQLConnect()
#
# STEP 1 - THREAD LOOP
#
def fnThreadLoop(i, queue, lock):

    s = requests.Session()

    while True:
        #exit Thread when detect signal to quit.
        while libextra.fnExitNow():
            try:
                r = queue.get_nowait()
                break
            except:
                #libextra.fnQueueEmpty(1,lock)
示例#4
0
#
cSQL_LIMIT = 20000
cTHREADS_CNT = 200

#
# FIRST STEPS
#
logg.info(
    '************** STARTING DRIVER **************** (Threads: %s)(SQL Limit: %s)',
    cTHREADS_CNT, cSQL_LIMIT)

QueueMaster = queue.Queue()
QueueUpdate = queue.Queue()
lock = threading.Lock()

cur = libextra.fnMySQLConnect()


#
# STEP 1 - THREAD LOOP
#
def fnThreadLoop(i, queue, lock):

    s = requests.Session()

    while True:
        #exit Thread when detect signal to quit.
        while libextra.fnExitNow():
            try:
                r = queue.get_nowait()
                break