def process_requests()

in process-requests/app.py [0:0]


def process_requests(requests, budget_dict) :
    
    for request in requests:
        request_id = request['rangeKey']
        budget = budget_dict[request['businessEntity']]
        logger.info("Available Budget while processing request {} is {}".format(request_id, budget))
        budget_amt = budget['budgetLimit']
        curr_req_status = request['requestStatus']
        requested_amt = request['pricingInfoAtRequest']['EstCurrMonthPrice'] #EstCurrMonthPrice
        requested_amt_monthly = request['pricingInfoAtRequest']['31DayPrice'] #EstCurrMonthPrice
        logger.info("Pricing info for request {} is {}".format(request_id, request['pricingInfoAtRequest']))
        blocked_amt = budget['accruedBlockedSpend']
        approved_amt = budget['accruedApprovedSpend']
        forecast_spend = budget['accruedForecastedSpend'] if budget['accruedForecastedSpend'] > 0 else budget['forecastedSpend']
        remaining_amt = budget_amt - forecast_spend - requested_amt_monthly - blocked_amt - approved_amt
        logger.info("Remaining Amount for request {} after calculation is {}".format(request_id, remaining_amt))
        if remaining_amt < 0 :
            logger.info("No Enough budget left for request {}".format(request_id))
            if curr_req_status == saved_req_status :
                logger.info("Request is in SAVED state, adjusting the local accruals before further processing... Request Id : {}".format(request_id))
                budget['accruedBlockedSpend'] = blocked_amt + requested_amt_monthly
            if not 'pendingRequestExists' in budget or not budget['pendingRequestExists'] or (not budget['budgetForecastProcessed'] and curr_req_status == pending_req_status):
                logger.info("There is no pending request exist for business entity or there is a pricing rebase.. update the status and notify admin. Request Id: {}".format(request_id))
                # mark the status of the request denoting waiting for approval
                update_request_status(request_id, pending_req_status, budget['rangeKey'])
                # send approval to admin
                notify_admin(request, budget)
                budget['pendingRequestExists'] = True
            elif curr_req_status == saved_req_status:
                logger.info('Pending request exists for business entity, keeping the request in blocked state {}'.format(request_id))
                # mark rest of the requests denoting blocked by a existing request
                update_request_status(request_id, blocked_req_status, budget['rangeKey'])
        else:
            logger.info('Request is within the budget, prepping to auto approve the request {}'.format(request_id))
            budget['accruedForecastedSpend'] = forecast_spend + requested_amt
            budget['accruedApprovedSpend'] = approved_amt + (requested_amt_monthly - requested_amt)
            # if request is in blocked state, it means that a blocked request is rejected, we must
            # deduct the blocked amount and add it forecast amount since we would added to blocked amt
            # when we marked this request as blocked
            if curr_req_status == blocked_req_status or curr_req_status == pending_req_status:
                budget['accruedBlockedSpend'] = blocked_amt - requested_amt_monthly
                budget['pendingRequestExists'] = False
            
            # approve the request
            approve_request(request_id,request['stackWaitUrl'])
            # mark the request status as auto approved by the system
            update_request_status(request_id, 'APPROVED_SYSTEM', budget['rangeKey'])