April 11, 2018 | Written by: Michael Behrendt
Categorized: Compute Services | How-tos
Share this post:
If you work with Cloud Functions, you know that building serverless applications mainly happens by creating actions–small pieces of code that each do one thing well.
You can of course sequence actions together or create event-driven workflows.
Through our work with customers, we have realized that some scenarios (for example, image processing, file processing, data pipelines) require more time to execute than the 5 minutes allowed.
Sure, being clever, you have figured out some tricks to get around the time limit–for example, by handing over state as part of invoking actions in sequence. In many situations, though, there either are no workarounds or increasingly tortuous ones. And in any case, the need to invent workarounds tells us it’s time for a change.
So based on that experience, we’re happy to announce that we have doubled the maximum time for executing an action from 5 to 10 minutes.
Keep in mind that any timeout value currently set on existing actions remains the same. You must manually change those, if change is needed.
Setting the timeout (CLI)
You use the ‘timeout’ parameter to set or reset the timeout for an action. These examples show how to do it via the CLI. Though the sample actions are in Node.js, the commands work exactly the same for actions in any other code language.
To set the timeout on a new action to 10 minutes, you add the ‘—timeout’ parameter to the ‘bx wsk action create’ command, setting the timeout value (in milliseconds):
bx wsk action create myNewAction myNewAction.js –timeout 600000
Similarly, to reset the timeout value on an existing action to 10 minutes, you add the ‘—timeout’ parameter to the ‘bx wsk action update’ command, again setting the value (in milliseconds):
bx wsk action update myExistingAction myExistingAction.js —timeout 600000
Setting the timeout (Web)
In the IBM Cloud web console, it takes just a few clicks to set a timeout:
- Use the navigation control (top left) to select Functions.
- Click Actions.
- For the relevant action, click the value under Timeout. The Runtime page opens.
- Type in a value (in seconds) or use -/+ to make small adjustments.
- Click Save.