skip to Main Content

i have a lot of firebase cloud functions with a timeout > 1m and every time I redeploy them it resets the timeout to 1m again. it takes a lot of time to always edit the timeout in the console after redeploying the functions. is there a way to set the timeout in the console or in the function itself?

exports.bgl = functions.pubsub
  .schedule("*/10 7-18 * * 1-6")
  .timeZone("Europe/Berlin")
  .onRun(async (context) => {
    const response = await fetch("https://www.bgl-zuerich.ch/vermietungen");
    const body = await response.text();

    const noFreeObjects = await body.search("Alle Wohnungen vermietet");

    if (noFreeObjects === -1) {
      sendEmail(
        "<div><h1>object found for bgl</h1><a href='https://www.bgl-zuerich.ch/vermietungen'>Link</a>" +
          body +
          "</div>",
        "[email protected]"
      );
    }
  });

2

Answers


  1. I don’t understand the relevance of the code you’re showing here. None of it looks like the complete code for a Cloud Functions. If you’re using the Firebase CLI to deploy your function, you can certainly set the timeout in the code that defines the function, and you should never have to changes it in the console. See the example in the documentation:

    To set memory allocation and timeout in functions source code, use the global options for memory and timeout seconds to customize the virtual machine running your functions. For example, this Cloud Storage function uses 1GiB of memory and times out after 300 seconds:

    exports.convertLargeFile = onObjectFinalized({
      timeoutSeconds: 300,
      memory: "1GiB",
    }, (event) => {
      // Do some complicated things that take a lot of memory and time
    });
    
    Login or Signup to reply.
  2. You can set the timeout for your Firebase Cloud Functions directly in the function’s code using the runWith method

    const functions = require('firebase-functions');
    
    exports.bgl = functions
      .runWith({ timeoutSeconds: 540 }) // Set timeout to 9 minutes (540 seconds)
      .pubsub
      .schedule("*/10 7-18 * * 1-6")
      .timeZone("Europe/Berlin")
      .onRun(async (context) => {
        const response = await fetch("https://www.bgl-zuerich.ch/vermietungen");
        const body = await response.text();
    
        const noFreeObjects = await body.search("Alle Wohnungen vermietet");
    
        if (noFreeObjects === -1) {
          sendEmail(
            "<div><h1>object found for bgl</h1><a href='https://www.bgl-zuerich.ch/vermietungen'>Link</a>" +
              body +
              "</div>",
            "[email protected]"
          );
        }
      });
    

    This code may help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search