def sys_exit(code): """a wrapper for sys.exit(), logs one line before exiting.""" callDur,recDur = calculate_durations() # # repeats the caller info: phone number, school, name. # if globals4signal.has_key('caller_dude'): caller = globals4signal['caller_dude'] logStr = '|| ' + caller.phone_number + ' || ' + \ caller.organization.alias + ' || ' + \ caller.__unicode__() + ' || ' if recDur == None or recDur == 0: # # we know there's a caller, but there's no recDur. # that means the person hung up before recording. # we'll put a call without recording in the event table. # event = Event( owner=caller, phone_number=caller.phone_number, action='CALL', etype='INF', call_duration=callDur, description='hangup before recording.') event.save() else: logStr = '' logStr += str(callDur) + ' || ' if recDur: logStr += str(recDur) dsh_utils.give_news('dsh_django1.sys_exit: ' + logStr, logging.info) sys.exit(code)
def hangup_signal_handler(signum, frame): """called after the hangup signal is received.""" global globals4signal dsh_utils.db_print2("dsh_failed.signal_handler: entered...", 116) time.sleep(1) calleeDshUid = globals4signal["callee_dsh_uid"] if is_triggered_by_dial_now(calleeDshUid): sys.exit(0) callee = dsh_django_utils.get_foreign_key(Person, calleeDshUid) if not callee: message = "dsh_failed: no such callee found: " + calleeDshUid dsh_utils.give_bad_news(message, logging.error) dsh_agi.report_event(message, reportLevel="ERR", sessionID=get_session()) sys.exit(1) else: dsh_utils.db_print("dsh_failed: found callee: " + repr(callee), 116) event = Event( owner=callee, phone_number=callee.phone_number, action="NOPU", etype="INF", description=".call not picked up. re-arming.", session=get_session(), ) event.save() dsh_django_utils.check_auto_timed_calls_for_person(callee, sessionID=get_session()) calleeInfo = dsh_django_utils.callee_info(callee) dsh_utils.give_news("dsh_failed.signal_handler: rearming callee: " + calleeInfo, logging.info)