node.js - BigQuery read ECONNRESET -
when using firebase cloud functions in combination google bigquery. error thrown randomly when function triggered.
this our error log:
error: read econnreset @ exports._errnoexception (util.js:1026:11) @ tlswrap.onread (net.js:569:26)
and here code colleague made.
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) beacons, count(distinct promotion.id) promotions, placeusers.users users', 'from `omega.sw_places` place', 'left join `omega.sw_promotions` promotion on promotion.place_id = place.id', 'left join `omega.sw_beacons` beacon on beacon.place_id = place.id', 'left join `omega.view_users_per_place` placeusers on placeusers.id = place.id', 'group place.id, placeusers.users' ].join(' '), params: [] }).then((data) => { const rows = data[0]; let result = {}; (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 big_query.js'); console.log(json.stringify(error)); return response.json({message: 'request failed!'}); }); };
what going wrong?
Comments
Post a Comment