android - 从 Postman 工作的 NODE JS Api 导致应用程序超时

标签 android node.js express salesforce

我有一个用 Express 框架编写的 Node js API。 我通过我的 api 发送一些数据,计算要制作的包的数量,例如:- 100/10 = 10 个要制作的包。 在 salesforce 和 firebase 中一一循环并创建包。

postman 的工作正常。

问题:

当我尝试从我的应用程序访问 api 时,当包计数 <= 10 时,它工作正常。当 > 10 时,假设 25 它计算包并运行 25 的循环并创建包,在第 11 次迭代后崩溃,重新启动路线,再次计算要创建 25 个包裹,并导致“超重错误”。

1-认为这是来自android错误,可能是我一个接一个地遇到了两个请求(事实并非如此)。 2-尝试发送 header “连接”“保持 Activity ”(正如 postman 所做的那样)不起作用。 3-尝试在下面的代码中设置超时,但它也不起作用(尝试了超时的变化,如 0、50,000 毫秒)

else {
            console.log('=====By Item=============');
            const supplierFinishedGood = {
                Name: parentBatchDoc['itemName'],
                Supplier_Product__c: parentBatchDoc['id'],
                Package_Size__c: 'a090S000001ZQ5kQAG', // Hard coded PackageSize in 'Gram' as per SALESFORCE
                On_Hand_Amount__c: childBatch['batchWeight']
            }
            console.log('=====By Item============= 2');
            const SupplierFinishedProductID = await createSupplierFinishedProduct(supplierFinishedGood, bearerToken);
            const Quantity_Packaged__c = Math.floor((childBatch['batchWeight'] - childBatch['batchTestAmount']) / noOfPackage);
            console.log('=====By Item============= 3');
            //console.log('Quantity_Packaged__c ==== Remaining_Grams_Available_for_Packaging__c', Quantity_Packaged__c, parentBatchSalesforce['Remaining_Grams_Available_for_Packaging__c']);

            for (let index = 0; index < noOfPackage; index++) {
                if (parentBatchSalesforce['Remaining_Grams_Available_for_Packaging__c'] > Quantity_Packaged__c) {
                    let package = {
                        Batch__c: childId,
                        Product__c: SupplierFinishedProductID,
                        Inventory_Location__c: 'a030S000003x7M7QAI', //Hard coded InventoryLocation 'StorageFinished' as per SALESFORCE
                        Number_Of_Items__c: noOfItemInPackage,
                        Quantity_Packaged__c: Quantity_Packaged__c,
                        Date_Packaged__c: datePackaged,
                        Expiration_Date__c: expirationDate
                    };
                    console.log('Before creating apcaktge ', index);
                    const packageID = await createPackage(package, bearerToken);
                    console.log('After creating package ', index, parentBatchSalesforce['Remaining_Grams_Available_for_Packaging__c']);

                    package['parentBatchId'] = parentId;
                    package['status'] = 'Ready to checkout';
                    package['uid'] = packageID;
                    const packageFBResponse = await db.collection('packages').doc(packageID).set(package, { merge: true });
                    reponseBody.push(packageID);
                } else {
                    console.log('======Over 
          Weight====');
}

Above code is what produces the error. 
There is a If condition before this it works fine i have tested it 
as it has some other scenario.

End result should not be a timeout error.
API should create all the packages and return the result.

最佳答案

我找到了解决方法。我正在处理批处理状态,我的代码返回了我需要的 ID,并创建了包。

这不是最终的最佳解决方案,而是一种解决方案。我仍然愿意知道实际问题是什么。

parentBatchDoc['childBatches'][childId]['batchStatus'] = "In Processing";
            const parentBatchDocResponse = await db.collection('batches').doc(parentId).set(parentBatchDoc, { merge: true });

if(parentBatchDoc['childBatches'][childId]['batchStatus'] !== "In Processing"){
    ===================Rest of the case of =======================
}

关于android - 从 Postman 工作的 NODE JS Api 导致应用程序超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57084249/

相关文章:

node.js - MongoDB 获取越来越多的记录

node.js - Express-Session、Connect-Redis 和 einaros/ws

javascript - 根据用户的输入创建查询

javascript - 类型错误 : task is not a function in async js parrallel

node.js - Sails.JS 如何将非 WWW 重定向到 WWW 以及将 HTTP 转发到 HTTPS

Android MapView 可拖动标记

android - 如何防止Android在连接USB设备时创建新的Activity?

java - Appium logcat 捕获失败 : spawn ENOENT (no spaces in path)

android - 更改 TabLayout 选项卡位置

node.js - 错误 : "user" defined in resolvers, 但不在架构中