Example #1
0
def update_status():
    """ Get voice call's result asynchronously """
    args = request.args if request.method == 'GET' else request.form
    log.info('Async results args: %s' % args.items())

    call_id = int(args.get('userField'))
    result = int(args.get('result'))

    voice_call = VoiceCall.get(call_id)
    voice_call.call_status = RESULT_STATUS_MAP[result]

    # unlock restaurant
    if voice_call.call_status == VoiceCall.STATUS_FAILED:
        restaurant_id = VoiceCall.get(call_id).restaurant_id
        unlock(get_rst_lock_key(restaurant_id))

    return {'result': 'success'}
Example #2
0
def update_status():
    """ Get voice call's result asynchronously """
    args = request.args if request.method == 'GET' else request.form
    log.info('Async results args: %s' % args.items())

    call_id = int(args.get('userField'))
    result = int(args.get('result'))

    voice_call = VoiceCall.get(call_id)
    voice_call.call_status = RESULT_STATUS_MAP[result]

    # unlock restaurant
    if voice_call.call_status == VoiceCall.STATUS_FAILED:
        restaurant_id = VoiceCall.get(call_id).restaurant_id
        unlock(get_rst_lock_key(restaurant_id))

    return {'result': 'success'}
Example #3
0
def voicecall_job():
    """ get calls from database, and send call request

    """
    not_dialed_calls = VoiceCall.get_by_status(VoiceCall.STATUS_NOT_DIAL)
    if not not_dialed_calls:
        return

    calls = _filter_calls(not_dialed_calls)
    if not calls:
        return

    for call in calls:
        # lock voice call
        if not lock(get_call_lock_key(call.id), time_out=30):
            continue

        # lock restaurant's line
        if lock(get_rst_lock_key(call.restaurant_id)):
            enqueue(BSTALK_TUBES['tube_vo'], voice_call_handler, call.id)
        else:
            unlock(get_call_lock_key(call.id))
Example #4
0
def voicecall_job():
    """ get calls from database, and send call request

    """
    not_dialed_calls = VoiceCall.get_by_status(VoiceCall.STATUS_NOT_DIAL)
    if not not_dialed_calls:
        return

    calls = _filter_calls(not_dialed_calls)
    if not calls:
        return

    for call in calls:
        # lock voice call
        if not lock(get_call_lock_key(call.id), time_out=30):
            continue

        # lock restaurant's line
        if lock(get_rst_lock_key(call.restaurant_id)):
            enqueue(BSTALK_TUBES['tube_vo'], voice_call_handler, call.id)
        else:
            unlock(get_call_lock_key(call.id))
Example #5
0
        restaurant_id = VoiceCall.get(call_id).restaurant_id
        VoicecallBan.add(restaurant_id, VoicecallBan.BAN_TYPE_TODAY)
        log.info('add voice call ban for restaurant {}'.format(restaurant_id))

    voice_order.key_pressed = key_pressed

    return {'result': 'success'}


def call_end_handler():
    """ get call end signal """
    args = request.args if request.method == 'GET' else request.form
    try:
        call_id = int(args.get('userField'))
    except TypeError, e:
        log.error(e)
        return {'result': 'Error! Arguments is not correctly provided.'}

    log.info('voicecall end_call args is {}'.format(args.items()))

    voice_call = VoiceCall.get(call_id)
    restaurant_id = voice_call.restaurant_id

    lock_key = get_rst_lock_key(restaurant_id)
    result = unlock(lock_key)
    if not result:
        log.warn('Voice call to restaurant [id: {}] may be timed out'.format(
            restaurant_id))

    return {'result': 'success'}
Example #6
0
        VoicecallBan.add(restaurant_id, VoicecallBan.BAN_TYPE_TODAY)
        log.info('add voice call ban for restaurant {}'.format(
            restaurant_id))

    voice_order.key_pressed = key_pressed

    return {'result': 'success'}


def call_end_handler():
    """ get call end signal """
    args = request.args if request.method == 'GET' else request.form
    try:
        call_id = int(args.get('userField'))
    except TypeError, e:
        log.error(e)
        return {'result': 'Error! Arguments is not correctly provided.'}

    log.info('voicecall end_call args is {}'.format(args.items()))

    voice_call = VoiceCall.get(call_id)
    restaurant_id = voice_call.restaurant_id

    lock_key = get_rst_lock_key(restaurant_id)
    result = unlock(lock_key)
    if not result:
        log.warn('Voice call to restaurant [id: {}] may be timed out'.
                 format(restaurant_id))

    return {'result': 'success'}