- Building Google Cloud Platform Solutions
- Ted Hunter Steven Porter Legorie Rajan PS
- 257字
- 2025-04-04 14:47:42
Background function retries and termination
Background functions support optional retries as a way to increase the likelihood of events being successfully processed when functions involve operations that may fail intermittently. Retries can be enabled when deploying via command line by providing the --retry flag, or in the Cloud Console when configuring triggers under Advanced options | Retry on failure.
Note that retries will be performed for up to seven days when retires are enabled. For this reason, Google recommends that a retry termination condition be included in the function definition, such as comparing the event's creation timestamp to the current time of execution.
As a convenience, background functions can be terminated in a number of ways. The primary way to terminate background functions is by simply invoking the provided callback function. Another option is to return anything or throw an exception. Lastly, a function may return a promise to allow potentially unfinished asynchronous operations to complete before termination. This can be convenient when performing multiple asynchronous operations or when leveraging third-party libraries that return promises.