0

How do you change execution timeout for a Google Cloud Function running a ExpressJS service in code?

I found the documentation for Google Functions to change the default timeout of 60 seconds for a simple function.

https://cloud.google.com/functions/docs/concepts/exec

exports.afterTimeout = (req, res) => {
  setTimeout(() => {
  // May not execute if function's timeout is <2 minutes
    console.log('Function running...');
    res.end();
  }, 120000); // 2 minute delay
};

Express

const express = require('express');
const app = express();

...
module.exports.app = app;

Thanks

1
  • I'm not clear. Are you asking if it's possible to change the timeout of the currently executing function programmatically? Or are you trying to change the timeout of the function for all future invocations? Or something else? Mar 6, 2019 at 4:50

1 Answer 1

0

Independently from what you run in your Cloud Function, when you deploy it using the gcloud command, you just need to set the --timeout flag to the value you want (in seconds), up to 9 minutes.

If you are using the Console to create you Cloud Function, there is a dropdown menu right above the "create" button that will show you the advanced options, where you can choose the timeout desired (between 1 and 540 seconds).

If you want to do it in execution time, from within the very function, you could do an API call to change the timeout. However, it will not affect any already running function execution.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.