O Cloud Deployment Manager vai chegar ao fim do suporte em 31 de dezembro de 2025. Se você usa o Deployment Manager, migre para o Infrastructure Manager ou uma tecnologia de implantação alternativa até 31 de dezembro de 2025 para garantir que seus serviços continuem sem interrupções.
É possível inspecionar uma variável para descobrir alterações chamando o método variables().watch. Com esse método, a variável é inspecionada por 60 segundos e retorna se o valor dela for alterado. Se o valor não for alterado em 60 segundos, o método será encerrado e retornará com a variável state=VARIABLE_STATE_UNSPECIFIED. Se a variável for excluída, o método retornará com uma variável state=DELETED e o último valor conhecido da variável.
Para definir um inspetor, use o Deployment Manager, a Google Cloud CLI ou a API.
Deployment Manager
Não há suporte para esse recurso no Deployment Manager. Em vez disso, crie um waiter.
[TIMEOUT_SEC] é o tempo de espera em segundos. O valor máximo e padrão é de 60 segundos.
A CLI gcloud inspeciona a variável e retorna depois que atinge o tempo limite especificado ou a variável é alterada. Quando ela é alterada, a resposta contém um dos estados de variável aplicáveis.
API
Na API, faça uma solicitação POST para o seguinte URI:
[CONFIG_NAME] é o nome do recurso RuntimeConfig para esta solicitação;
[VARIABLE_KEY] é a chave a ser observada.
Opcionalmente, é possível fornecer um payload de solicitação com a propriedade newerThan:
{"newerThan": "[TIMESTAMP]"}
em que [TIMESTAMP] é um carimbo de data/hora RFC 3339 desde epoch no formato UTC "Zulu". Por exemplo:
2014-10-02T15:01:23.045123456Z
Se você fornecer a propriedade newerThan, o método retornará imediatamente se o carimbo de data e hora atual da variável for mais recente do que o carimbo de data e hora especificado.
Use a propriedade newerThan para garantir que você não perdeu nenhuma alteração entre as chamadas watch().
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-19 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)."]]