javascriptfirebasegoogle-cloud-functionsenvironment-variables

How do I use Parameterized configuration with Firebase Functions onSchedule?


I am trying to use environment variables with onSchedule. But it only accepts a string, not an Expression<string> or similar. Although value() makes it compile, it will not actually deploy.

Can I use onSchedule with Parameterized configuration as recommended in the docs? Or do I need to fall back to environment variables?

import { onSchedule } from "firebase-functions/v2/scheduler";
import { defineString} from "firebase-functions/params";

const schedule = defineString("REFRESH_SCHEDULE");

export const refreshSchedule = onSchedule(
  {
    schedule: schedule, // Adding .value() makes it compile, but then it doesn't deploy.
  },
  async () => {
    // Do Stuff
  }
);

Solution

  • It's not possible. Take a look at the ScheduleOptions definition for onSchedule from the source code:

    export interface ScheduleOptions extends options.GlobalOptions {
      /** The schedule, in Unix Crontab or AppEngine syntax. */
      schedule: string;
    
      /** The timezone that the schedule executes in. */
      timeZone?: timezone | Expression<string> | ResetValue;
    
      /** The number of retry attempts for a failed run. */
      retryCount?: number | Expression<number> | ResetValue;
    
      /** The time limit for retrying. */
      maxRetrySeconds?: number | Expression<number> | ResetValue;
    
      /** The minimum time to wait before retying. */
      minBackoffSeconds?: number | Expression<number> | ResetValue;
    
      /** The maximum time to wait before retrying. */
      maxBackoffSeconds?: number | Expression<number> | ResetValue;
    
      /** The time between will double max doublings times. */
      maxDoublings?: number | Expression<number> | ResetValue;
    }
    

    You can see that it doesn't accept an Expression type value, which means that values created by defineString aren't valid. There is likely some specific reason for this, but if this is very important to your use case, you might want to explain that in a new issue on GitHub.