I have a firebase v2 function set to timeout in 540 seconds however httpsCallableFromURL
catches with an error saying Firebase Error: deadline-exceeded
before the function finishes.
Here's the template of my firebase function:
exports.functionname = functions.https.onCall(
{
timeoutSeconds: 540,
cpu: 2,
},
async (req) => {
const getOutput = async (id: string) => {
return new Promise((resolve, reject) => {
return axios.get('ur'l)
.then((res) => {
resolve(res.data)
})
.catch((e) => {
resolve(false)
})
})
}
let output: any
const recurse = async () => {
return new Promise(async (resolve) => {
// first try getting output
output = await getOutput(id).then((res) => {
return res
})
// check for output
if (output.output) {
return resolve(true)
} else if (output.error) {
return resolve(false)
} else {
setTimeout(() => {
return resolve(recurse())
}, 2000)
}
})
}
return recurse()
.then(async () => {
const imageUrl = output.output[0]
function getBase64(url: string) {
return axios
.get(url, {
responseType: 'arraybuffer',
})
.then((response) =>
Buffer.from(response.data, 'binary').toString('base64'),
)
}
const base64Image = await getBase64(imageUrl)
const data = {
type: 'image',
predictionId,
result: base64Image,
}
return data
}
})
.catch((e) => {
return false
})
},
)
If I monitor the function logs it ends up finishing within the 540 seconds but my client never receives the return value since the httpsCallableFromURL
errored out.