benomatis
benomatis

Reputation: 5643

repeated firebase deploy functions pub/sub creates duplicate scheduler jobs

I use the following command to deploy my project, one of the functions being a pub/sub:

firebase deploy --only functions

...and everything happens just fine, but the scheduler job is created a 2nd time, an exact copy of the previous one every time I deploy again.

I don't change the pub/sub function, so I would not necessarily need to include it during deploy, but why is it creating a new scheduler job every time? Neither the function, nor the topic in Pub/Sub is duplicating, only the scheduler job - why?

Here is how the pubsub function looks like, if relevant:

export const scheduledStuff = functions.pubsub
  .schedule('0 0 * * *')
  .timeZone('America/New_York')
  .onRun(() => {
    // do stuff
  })

Update Jun 17 2022: I didn't specifically mention this, but the code I gave above, I hoped, should have given it away: I'm using the ES6 annotation for the function, ie. use import instead of require for packages, and the function is exported as export const scheduledStuff... instead of exports.scheduledStuff....

My functions are then separated into 2 categories, functions:functions, which are all the functions that are NOT pubsub, and this one pubsub. This is because I wanted to prevent the deployment of the pubsub function to my staging environment, so I'm using firebase deploy --only functions:functions for that one.

For this purpose I have an index file in my main functions directory that looks something like this:

import { default as firstFunction } from './callables/firstFunction.js'
import { default as secondFunction } from './callables/secondFunction.js'
//...

export const functions = {
    firstFunction,
    secondFunction,
    //...
}

import { scheduledStuff } from './pubsub/scheduledStuff.js'

export const pubSubStuff = { scheduledStuff }

Upvotes: 0

Views: 248

Answers (1)

Priyashree Bhadra
Priyashree Bhadra

Reputation: 3607

I tried to reproduce your case by deploying the below scheduler function which will run every minute and create a pubsub topic and a scheduler job. enter image description here enter image description here

In my case, my first deploy firebase deploy –only functions created a pubsub topic firebase-schedule-scheduledFunctionCrontab-us-central1 and a scheduler job firebase-schedule-scheduledFunctionCrontab-us-central.

enter image description here With the second deployment firebase deploy –only functions, neither a duplicate scheduler job was created nor a duplicate pubsub topic.

My terminal shows the below lines:

functions: updating Node.js 16 function scheduledFunctionCrontab(us-central1)...
✔ functions[scheduledFunctionCrontab(us-central1)] Successful update operation.

The last deployment run got updated but a duplicate is not created. Also the scheduler function keeps updating the last run time and next run time field which confirms that the function is running every minute.

If what you have shared here, is the entire code of your scheduler function, then I think this is a Customer issue/bug. Still to confirm I would like to have a look at your logs, but if you are confident that this is not an intended behavior (which seems to be according to me) please raise a support ticket with Google Cloud Support or raise a Customer issue in a public issue tracker

Upvotes: 1

Related Questions