0

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
  }
);

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you know if it's possible to have different schedules based on my Firebase project (environment) through some other means?
You can use scheduled tasks to write code to arrange for things to happen on whatever schedule or conditions you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.