Cloud Deployment Manager dejará de estar disponible el 31 de diciembre de 2025. Si actualmente usas Deployment Manager, migra a Infrastructure Manager o a una tecnología de implementación alternativa antes del 31 de diciembre de 2025 para asegurarte de que tus servicios continúen sin interrupciones.
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta página se explica cómo crear un recurso de espera para una variable. Para obtener más información sobre los recursos de espera, consulta Conceptos básicos de Runtime Configurator.
Para observar una variable a fin de detectar cambios, llama al método variables().watch. El método observa la variable durante 60 segundos y se muestra si el valor de la variable cambia. Si el valor no cambia en 60 segundos, el método finaliza y muestra la variable state=VARIABLE_STATE_UNSPECIFIED. Si se borra la variable, el método muestra una variable state=DELETED y el último valor de variable conocido.
Para configurar un agente de observación, usa Deployment Manager, Google Cloud CLI o la API.
Deployment Manager
Esto no se admite en Deployment Manager. Crea un recurso de espera en su lugar.
[TIMEOUT_SEC] es el tiempo en segundos que se esperará. La cantidad predeterminada y máxima es 60 segundos.
Gcloud CLI observa la variable y aparece una vez que alcanza el tiempo de espera especificado o si cambia la variable. Si la variable cambió, la respuesta contiene uno de los estados de variable aplicables.
API
En la API, realiza una solicitud POST al siguiente URI:
[PROJECT_ID] es el ID del proyecto de esta solicitud.
[CONFIG_NAME] es el nombre del recurso RuntimeConfig para esta solicitud.
[VARIABLE_KEY] es la clave que se observará.
De manera opcional, puedes proporcionar una carga útil de solicitud con la propiedad newerThan:
{"newerThan": "[TIMESTAMP]"}
donde [TIMESTAMP] es una marca de tiempo en RFC 3339 desde el ciclo de entrenamiento en formato "zulú" UTC. Por ejemplo:
2014-10-02T15:01:23.045123456Z
Si proporcionas la propiedad newerThan, el método se muestra de inmediato si la marca de tiempo actual para la variable es más nueva que la marca de tiempo especificada.
Usa la propiedad newerThan para asegurarte de no se perdió ningún cambio entre llamadas watch().
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-03 (UTC)"],[[["\u003cp\u003eThis page guides users on how to watch a variable for changes using the \u003ccode\u003evariables().watch\u003c/code\u003e method, which monitors a variable for 60 seconds and reports any changes or if the variable is deleted.\u003c/p\u003e\n"],["\u003cp\u003eTo use the \u003ccode\u003egcloud\u003c/code\u003e command-line tool for watching a variable, use the command \u003ccode\u003egcloud beta runtime-config configs variables watch [VARIABLE_KEY] --max-wait [TIMEOUT_SEC] --config-name [CONFIG_NAME]\u003c/code\u003e, with a maximum wait time of 60 seconds.\u003c/p\u003e\n"],["\u003cp\u003eThe API method \u003ccode\u003evariables().watch\u003c/code\u003e can be used to watch variables, and it allows for the optional \u003ccode\u003enewerThan\u003c/code\u003e property to check if any changes have been missed since the last watch call, and if the variable value is newer than the specified \u003ccode\u003enewerThan\u003c/code\u003e timestamp it will return immediately.\u003c/p\u003e\n"],["\u003cp\u003eDeployment Manager does not support creating a watcher for a variable, and users are instead advised to create a waiter.\u003c/p\u003e\n"],["\u003cp\u003eThis feature is in beta, which means it is subject to the "Pre-GA Offerings Terms", is available "as is," and may have limited support.\u003c/p\u003e\n"]]],[],null,["# Watching a Variable for Changes\n\n| **Beta**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page explains how to create a watcher for a variable. To learn more\nabout watchers, see\n[Runtime Configurator Fundamentals](/deployment-manager/runtime-configurator).\n\nBefore you begin\n----------------\n\n- If you want to use the command-line examples in this guide, install the [\\`gcloud\\` command-line tool](/sdk).\n- If you want to use the API examples in this guide, set up [API access](/deployment-manager/docs/reference/latest).\n- Read [Runtime Configurator Fundamentals](/deployment-manager/runtime-configurator).\n- Read [Creating and Deleting RuntimeConfig Resources](/deployment-manager/runtime-configurator/create-and-delete-runtimeconfig-resources).\n- Read [Setting and Getting Data](/deployment-manager/runtime-configurator/set-and-get-variables).\n\nWatching a variable for change\n------------------------------\n\nYou can watch a variable for changes by calling the\n[`variables().watch`](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables/watch)\nmethod. The method watches the variable for 60 seconds and returns if the variable\nvalue changes. If the value doesn't change within 60 seconds, the method\nterminates and returns with variable `state=VARIABLE_STATE_UNSPECIFIED`. If\nthe variable is deleted, the method returns with a variable `state=DELETED` and\nthe last known variable value.\n\nTo set a watcher, use Deployment Manager, the Google Cloud CLI, or the\nAPI. \n\n### Deployment Manager\n\nThis is not supported in Deployment Manager. Create a\n[waiter](/deployment-manager/runtime-configurator/creating-a-waiter)\ninstead.\n\n### gcloud\n\nWith the Google Cloud CLI: \n\n gcloud beta runtime-config configs variables watch [VARIABLE_KEY] --max-wait [TIMEOUT_SEC] --config-name [CONFIG_NAME]\n\nwhere:\n\n- `[VARIABLE_KEY]` is the key to watch.\n- `[TIMEOUT_SEC]` is the time in seconds to wait. The default and maximum amount is 60 seconds.\n\nThe gcloud CLI watches the variable and returns after it reaches the\nspecified timeout period or the variable changes. If the variable changed,\nthe response contains one of the applicable\n[variable states](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables#VariableState).\n\n### API\n\nIn the API, make a `POST` request to the following URI: \n\n https://runtimeconfig.googleapis.com/v1beta1/projects/[PROJECT_ID]/configs/[CONFIG_NAME]/variables/[VARIABLE_KEY]:watch\n\nwhere:\n\n- `[PROJECT_ID]` is the project ID for this request.\n- `[CONFIG_NAME]` is the name of the RuntimeConfig resource for this request.\n- `[VARIABLE_KEY]` is the key to watch.\n\n Optionally, you can provide a request payload with the `newerThan` property:\n\n {\n \"newerThan\": \"\\[TIMESTAMP\\]\"\n }\n\n where `[TIMESTAMP]` is a timestamp in RFC 3339 since the epoch in UTC \"Zulu\"\n format. For example:\n\n 2014-10-02T15:01:23.045123456Z\n\n If you provide the `newerThan` property, the method returns immediately if the\n current timestamp for the variable is newer than the specified timestamp.\n Use the `newerThan` property to make sure you didn't miss any changes\n between `watch()` calls.\n\n The method returns with one of applicable\n [variable states](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables#VariableState).\n\n To learn more about the method, read the\n [`variables().watch`](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables/watch)\n documentation.\n\nWhat's next\n-----------\n\n- Learn about [Runtime Configurator](/deployment-manager/runtime-configurator).\n- [Setting and Getting Data](/deployment-manager/runtime-configurator/set-and-get-variables).\n- [Creating a Waiter](/deployment-manager/runtime-configurator/creating-a-waiter).\n- [Creating and Deleting RuntimeConfig Resources](/deployment-manager/runtime-configurator/create-and-delete-runtimeconfig-resources).\n- Refer to the [v1beta1 reference](/deployment-manager/runtime-configurator/reference/rest).\n- Refer to the [Quotas for Runtime Configurator](/deployment-manager/pricing-and-quotas#runtime_configurator)."]]