firebase-functions
firebase-functions copied to clipboard
V1 schedule.onRun doesn't call onInit
firebase-functions: 6.3.2
If creating a schedule.onRun function, onInit is not called because of this lines:
Will set label deployment-scheduled to true https://github.com/firebase/firebase-functions/blob/cce55b562f325474a2ea13d7db06392309667990/src/v1/providers/pubsub.ts#L155
makeCloudFunction is wrapping withInit on the first line https://github.com/firebase/firebase-functions/blob/cce55b562f325474a2ea13d7db06392309667990/src/v1/cloud-functions.ts#L370
However, because of the deployment-scheduled label it uses the non wrapped handler: https://github.com/firebase/firebase-functions/blob/cce55b562f325474a2ea13d7db06392309667990/src/v1/cloud-functions.ts#L411
Expected behavior
onInit callback is called
Actual behavior
onInit is not called and causes issues with the function execution
I found a few problems with this issue:
- I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
- This issue does not seem to follow the issue template. Make sure you provide all the required information.
Hi @tecbot,
Thanks for reporting this issue! We’ve received it and are reviewing it. We’ll provide updates as soon as possible.
If you have time, could you produce some code that demonstrates this issue?
I already referenced the misleading code lines. Creating a v1 pubsub trigger will cause the issue always:
import { onInit } from 'firebase-functions'
import * as functions from 'firebase-functions/v1'
import { info } from 'firebase-functions/logger'
onInit(() => {
info("onInit called")
})
export const myFunction = functions
.pubsub.schedule('*/10 * * * *')
.onRun(() => {
info("function executed")
})
Expected log output:
- onInit called
- function executed
Actual:
- function executed
Appreciate it! It's just so whoever picks this up can easily reproduce and also use it to verify their fix works.
Reproduced