Exemple #1
0
def main():
    strEDIName = File.getCurrentFileName(__file__)
    strEDIPath = os.getcwd()

    jsonEDIService = Common.loadJsonFile(strEDIName + ".json")
    strEDIID = jsonEDIService["id"]

    strEDIConnection = Common.filterJsonListFirst(jsonEDIService["connectionList"], "connectionID", "maria-dw-DWuser-DWWANT")["connection"]
    strEDIDB = Common.filterJsonListFirst(jsonEDIService["connectionList"], "connectionID", "maria-dw-DWuser-DWWANT")["db"]

    intIntervalSeconds = jsonEDIService["intervalSeconds"]
    intFileBlockSize = jsonEDIService["fileBlockSize"]

    strMessageSMTPServer = jsonEDIService["messageSMTPServer"]
    strMessageSMTPFrom = jsonEDIService["messageSMTPFrom"]
    arrayMessageSMTPSuccessTo = jsonEDIService["messageSMTPSuccessToList"]
    arrayMessageSMTPFailureTo = jsonEDIService["messageSMTPFailureToList"]

    strLogDate = Common.setLogging(strEDIID)
    logger = logging.getLogger(strEDIID)

    logger.info("Load EDIFlows.json file.")
    jsonEDIFlows = Common.loadJsonFile(strEDIName + "Flows.json")

    try:

        logger.warning("Start EDI Service.")
        while True:
            strNowDate = Common.getDateSimple(datetime.datetime.now())
            if strNowDate != strLogDate:
                strLogDate = Common.setLogging(strEDIID)
                logger = logging.getLogger(strEDIID)

            EDIBase.validateSchedule(strEDIConnection, strEDIDB, jsonEDIFlows, intIntervalSeconds)
            EDIBase.executeWaitingFlows(strEDIPath, strEDIConnection, strEDIDB, jsonEDIFlows, 
                intFileBlockSize, strMessageSMTPServer, strMessageSMTPFrom, arrayMessageSMTPSuccessTo, arrayMessageSMTPFailureTo)
            EDIBase.deleteFlowLog(jsonEDIFlows)

            time.sleep(intIntervalSeconds)

    except Exception:
        strExceptionMessage = traceback.format_exc()
        logger.error(strExceptionMessage)

        strMessageSMTPSubject = "!!!!! {ediID} Exception !!!!!".format(ediID=strEDIID)
        Message.sendSMTPMail(strMessageSMTPServer, strMessageSMTPFrom, arrayMessageSMTPFailureTo, strMessageSMTPSubject, strExceptionMessage, None, None)
        
        logger.error("Stop EDI Service by Exception.")
    finally:
        logger.warning("Stop EDI Service.")
Exemple #2
0
def executeWaitingFlows(strEDIPath, strEDIConnection, strEDIDB, jsonEDIFlows,
                        intFileBlockSize, strMessageSMTPServer,
                        strMessageSMTPFrom, arrayMessageSMTPSuccessTo,
                        arrayMessageSMTPFailureTo):
    listWaitingFlows = EDIEntity.getWaitingFlowList(strEDIConnection, strEDIDB,
                                                    jsonEDIFlows["ediID"])
    if len(listWaitingFlows) > 0:
        for listWaitingFlow in listWaitingFlows:
            jsonFlow = Common.filterJsonListFirst(
                jsonEDIFlows["flowList"], "flowID",
                listWaitingFlow["EDI_FLOW_ID"])
            strRunningFlow = jsonEDIFlows["ediID"] + "." + jsonFlow[
                "flowID"] + ".run"
            if jsonFlow != None and os.path.exists(strRunningFlow) == False:
                fileRunningFlow = open(strRunningFlow, "w")
                fileRunningFlow.close()

                thread = threading.Thread(
                    target=executeFlow,
                    args=(strEDIPath, jsonEDIFlows["ediID"], strEDIConnection,
                          strEDIDB, listWaitingFlow, jsonFlow,
                          intFileBlockSize, strMessageSMTPServer,
                          strMessageSMTPFrom, arrayMessageSMTPSuccessTo,
                          arrayMessageSMTPFailureTo))
                thread.start()
            else:
                pass
    return True