首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BigQuery读取ECONNRESET

BigQuery读取ECONNRESET
EN

Stack Overflow用户
提问于 2017-04-08 04:16:18
回答 1查看 675关注 0票数 4

当将Firebase Cloud Functions与谷歌BigQuery结合使用时。有时,当触发此函数时,会随机抛出错误。

这是我们的错误日志:

代码语言:javascript
复制
Error: read ECONNRESET
    at exports._errnoException (util.js:1026:11)
    at TLSWrap.onread (net.js:569:26)

这是我同事写的代码。

代码语言:javascript
复制
const bigQuery = require('@google-cloud/bigquery');
const admin = require('firebase-admin');
const database = admin.database();

exports.updateAllPlaceStatistics = (request, response) => {
    const secret = request.query['secret'];

    if (secret !== 'secret') {
        return response.json({message: 'Request failed!'});
    }

    const big = bigQuery();

    return big.query({
        query: [
            'SELECT place.id, COUNT(DISTINCT beacon.id) as beacons, COUNT(DISTINCT promotion.id) as promotions, placeUsers.users as users',
            'FROM `omega.sw_places` as place',
            'LEFT JOIN `omega.sw_promotions` as promotion ON promotion.place_id = place.id',
            'LEFT JOIN `omega.sw_beacons` as beacon ON beacon.place_id = place.id',
            'LEFT JOIN `omega.view_users_per_place` as placeUsers ON placeUsers.id = place.id',
            'GROUP BY place.id, placeUsers.users'
        ].join(' '),
        params: []
    }).then((data) => {
        const rows = data[0];

        let result = {};
        for (let index = 0; index < rows.length; index++) {
            const item = rows[index];

            result[item.id] = {
                beacons: item.beacons,
                promotions: item.promotions
            };
        }

        return database.ref('statistics/general').set(result);
    }).then(() => {
        return response.json({message: 'Request succeeded!'});
    }).catch((error) => {
        console.log('An error has happened to the big_query.js');
        console.log(JSON.stringify(error));

        return response.json({message: 'Request failed!'});
    });
};

哪里出了问题?

EN

回答 1

Stack Overflow用户

发布于 2018-07-31 04:29:20

尝试从return database.ref('statistics/general').set(result);中删除return

返回promise resolved将结束函数的执行。在这种情况下,您的.set()在BigQuery之前结束,它在BigQuery之前结束函数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43286453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档