Example #1
0
def send_msg(name_part, dtime_part, func):
    """
    Register the execution on redis server and if the func is not null
    execute func like func[0](*func[1]).
    """
    data = RedisData(connection_pool=CPOOL)
    try:
        if func:
            func[0](*func[1])
        data.set(dtime_part + name_part, 1)
    except Exception as ex:
        logging.exception(ex)
        print(ex)
Example #2
0
def heimdall_verification():
    """
Execute all verifications of old HeimdallWeb Application.
    """
    today = date.today()
    now = datetime.now()
    now_time = datetime.now().time()
    drvrs = 'drivers'
    flts = 'faults'
    atmtc = 'automatic_reports'
    prdctvt = 'os_productivity'
    gtdjsts = 'gate_adjusts'
    mpls = 'employees'
    jrn = 'journey'
    wdgts = 'widgets'
    data = RedisData()
    many_results = verify_all_checks()
    data.set('portal_report_hours', many_results[0],
             expire=timedelta(minutes=5))
    for emp in many_results[1].keys():
        for this_time in many_results[1][emp].keys():
            if not msg_has_been_sent(mpls + emp, this_time.strftime('%H:%M')):
                for result in many_results[1][emp][this_time]:
                    send_msg(mpls + emp, this_time.strftime('%H:%M'), result)
    tmp = list(data.get_all(today.strftime('%Y%m%d') + atmtc).values())
    result = verify_automatic_reports(now, tmp)
    for key in result[0]:
        data.set(today.strftime('%Y%m%d') + atmtc + str(key), key)
    for func in result[1]:
        try:
            func[0](*func[1])
        except Exception as err:
            logging.exception(err)
            print(err)
    extra_hours = verify_extra_hours()
    for emp in extra_hours.keys():
        for this_time in extra_hours[emp].keys():
            if not msg_has_been_sent(mpls + emp,
                                     this_time.strftime('%H:%M')):
                try:
                    send_msg(mpls + emp, this_time.strftime('%H:%M'),
                             extra_hours[emp][this_time])
                except Exception as err:
                    logging.exception(err)
                    print(err)
    if now_time >= time(6, 0):
        if not msg_has_been_sent(prdctvt, today.strftime('%Y%m%d')):
            try:
                result = verify_os_productivity()
                send_msg(prdctvt, today.strftime('%Y%m%d'), result)
            except Exception as err:
                logging.exception(err)
                print(err)
    if now_time >= time(6, 10):
        if not msg_has_been_sent(gtdjsts, today.strftime('%Y%m%d')):
            try:
                data.set(today.strftime('%Y%m%d') + gtdjsts, 1)
                verify_gate_adjusts()
            except Exception as err:
                logging.exception(err)
                print(err)
    if now_time >= time(7, 0):
        if not msg_has_been_sent(wdgts, today.strftime('%Y%m%d')):
            data.set(today.strftime('%Y%m%d') + wdgts, 1)
            for w in Query(Report).get(is_widget=True):
                Process(target=WidgetsData().update_data,
                        args=[w.id]).start()
    if now_time >= time(8, 0):
        if not msg_has_been_sent(jrn, today.strftime('%Y%m%d')):
            try:
                result = verify_week_journey()
                send_msg(jrn, today.strftime('%Y%m%d'), result)
            except Exception as err:
                logging.exception(err)
                print(err)
    if now_time >= time(8, 3):
        if not msg_has_been_sent(drvrs, today.strftime('%Y%m%d')):
            try:
                result = verify_drivers()
                send_msg(drvrs, today.strftime('%Y%m%d'), result)
            except Exception as err:
                logging.exception(err)
                print(err)
    if now_time >= time(8, 6):
        if not msg_has_been_sent(flts, today.strftime('%Y%m%d')):
            try:
                result = verify_faults()
                send_msg(flts, today.strftime('%Y%m%d'), result)
            except Exception as err:
                logging.exception(err)
                print(err)
    logging.threading.Timer(30, heimdall_verification).start()