This topic was automatically generated from Slack. You can find the original thread here.
while using this code sometimes I am getting this error
This step was still trying to run code when the step ended. Make sure you promisify callback functions and await all Promises. (Reason: TLSSocket, )
but sometimes it works fine how to solve this ??
import lodash from’lodash’
import { WebClient } from ‘@slack/web-api’;
import admin from ‘firebase-admin’;
import {Storage} from ‘@google-cloud/storage’
export default defineComponent({
props: {
google_cloud: {
type: “app”,
app: “google_cloud”,
},
firebase_admin_sdk: {
type: “app”,
app: “firebase_admin_sdk”,
}
},
async run({steps, $}) {
const { projectId, clientEmail, privateKey } = this.firebase_admin_sdk.$auth
const formattedPrivateKey = privateKey.replace(/\n/g, ‘\n’)
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.cert({
projectId,
clientEmail,
privateKey: formattedPrivateKey,
})
})
}
const key = JSON.parse(this.google_cloud.$auth.key_json)
const storage = new Storage({
projectId: key.project_id,
credentials: {
client_email: key.client_email,
private_key: key.private_key,
}
})
try{
async function getProjectFinancialTasksData() {
//some code to get data
return projectFinanacialTasks
}
async function removeProjectFinanacialTask(collection) {
const db_data = admin.firestore();
let collectionRef = db_data.collection(collection)
const snapshot = await collectionRef.get();
const deletePromises = snapshot.docs.map(doc => doc.ref.delete());
await Promise.all(deletePromises);
const snapshot1 = await collectionRef.get();
}
async function uploadProjectFinanacialTasks(projectFinanacialTasks, collection) {
//some code to upload documents to collectino
}
let collection ="collection-name"
let projectFinanacialTasks=await getProjectFinancialTasksData()
await removeProjectFinanacialTask(collection)
await uploadProjectFinanacialTasks(projectFinanacialTasks, collection)
}catch(e){
console.log(e)
$.flow.exit()
}
},
})