This page explains how to create a watcher for a variable. To learn more about watchers, see Runtime Configurator Fundamentals.
Before you begin
- If you want to use the command-line examples in this guide, install the `gcloud` command-line tool.
- If you want to use the API examples in this guide, set up API access.
- Read Runtime Configurator Fundamentals.
- Read Creating and Deleting RuntimeConfig Resources.
- Read Setting and Getting Data.
Watching a variable for change
You can watch a variable for changes by calling the
variables().watch
method. The method watches the variable for 60 seconds and returns if the variable
value changes. If the value doesn't change within 60 seconds, the method
terminates and returns with variable state=VARIABLE_STATE_UNSPECIFIED
. If
the variable is deleted, the method returns with a variable state=DELETED
and
the last known variable value.
To set a watcher, use Deployment Manager, the Google Cloud CLI, or the API.
Deployment Manager
This is not supported in Deployment Manager. Create a waiter instead.
gcloud
With the Google Cloud CLI:
gcloud beta runtime-config configs variables watch [VARIABLE_KEY] --max-wait [TIMEOUT_SEC] --config-name [CONFIG_NAME]
where:
[VARIABLE_KEY]
is the key to watch.[TIMEOUT_SEC]
is the time in seconds to wait. The default and maximum amount is 60 seconds.
The gcloud CLI watches the variable and returns after it reaches the specified timeout period or the variable changes. If the variable changed, the response contains one of the applicable variable states.
API
In the API, make a POST
request to the following URI:
https://runtimeconfig.googleapis.com/v1beta1/projects/[PROJECT_ID]/configs/[CONFIG_NAME]/variables/[VARIABLE_KEY]:watch
where:
[PROJECT_ID]
is the project ID for this request.[CONFIG_NAME]
is the name of the RuntimeConfig resource for this request.[VARIABLE_KEY]
is the key to watch.Optionally, you can provide a request payload with the
newerThan
property:{ "newerThan": "[TIMESTAMP]" }
where
[TIMESTAMP]
is a timestamp in RFC 3339 since the epoch in UTC "Zulu" format. For example:2014-10-02T15:01:23.045123456Z
If you provide the
newerThan
property, the method returns immediately if the current timestamp for the variable is newer than the specified timestamp. Use thenewerThan
property to make sure you didn't miss any changes betweenwatch()
calls.The method returns with one of applicable variable states.
To learn more about the method, read the
variables().watch
documentation.
What's next
- Learn about Runtime Configurator.
- Setting and Getting Data.
- Creating a Waiter.
- Creating and Deleting RuntimeConfig Resources.
- Refer to the v1beta1 reference.
- Refer to the Quotas for Runtime Configurator.