これは私のコードです
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const axios = require('axios');
admin.initializeApp(functions.config().functions);
exports.sendNotifications = functions
.region('europe-west1')
.pubsub.schedule('every day 04:00').onRun(async context => {
axios.get('http://niksimoni.pythonanywhere.com/api/pulizie_domani')
.then(listOfStreets => {
const streets = listOfStreets.data.strade;
const promises = [];
for (const street of streets) {
const p = axios.get('http://niksimoni.pythonanywhere.com/api/data_pulizie?indirizzo=' + street)
.then(listOfHours => {
const ora = listOfHours.data.ora;
var topic = street.split(" ").join("-");
var message = {
data: {
title: street,
subtitle: 'Pulizia domani alle ' + ora,
},
topic: topic
};
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
})
promises.push(p);
}
return Promise.all(promises);
})
.catch(error => {
console.log(error);
});
});
axiosをリクエストに置き換えようとしましたが、何を変更しても問題は解決しませんでした。常に次のエラーが発生します。 'リクエストの作成中にエラーが発生しました:安全なTLS接続が確立される前にクライアントネットワークソケットが切断されました。エラーコード:ECONNRESET'promiseの処理方法を学習しようとしましたが、理解できたと思いましたが、間違っている可能性があります。どんな助けもいただければ幸いです
クラウド関数内で常にpromiseを返します。
return axios.get('http://niksimoni.pythonanywhere.com/api/pulizie_domani')
そしてこれも:
return admin.messaging().send(message)
そうしないと、クラウド関数が実行中のコードを突然強制終了します。キャッチブロックについても同じことをしたいと思うかもしれません。詳細については、https://firebase.google.com/docs/functions/terminate-functionsをご覧ください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加