When you configure Google Cloud Functions, you can set the Timeout property of the function. This property specifies the amount of time that the function will keep running if you do not complete the function. The default timeout is set to 60 seconds.
While this might look ok, keep in mind that when it comes to Cloud Functions pricing, one key factor you are charged for is the amount of time that the functions are running. So you want to keep this to a minimum and not let it timeout.
As a best practice, you should use the appropriate mechanism to complete the function as soon as possible and this depends on Function type.
- HTTP Functions: Invoke the the
send()
,resend()
or theend()
methods on the Express JS response once you are done with the functionality. - Cloud Storage and Pub/Sub Functions: Invoke the
callback()
function once you are done.
This will prevent the function from being kept running till the timeout
occurs, thereby saving you money since you are charged
for the time that the function executes.
I set my cloud function to 540 seconds but it keeps timing out after 60 seconds anyway. I've added more memory to it too. Not sure what else to try/why the time out setting is not being taken into account