Der Support für Cloud Deployment Manager endet am 31. Dezember 2025. Wenn Sie derzeit Deployment Manager verwenden, müssen Sie bis zum 31. Dezember 2025 zu Infrastructure Manager oder einer alternativen Bereitstellungstechnologie migrieren, damit Ihre Dienste ohne Unterbrechung weiterlaufen.
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird erklärt, wie ein Watcher für eine Variable erstellt wird. Weitere Informationen zu Watchers finden Sie in Grundlagen des Runtime Configurators.
Hinweis
Wenn Sie die Befehlszeilenbeispiele in dieser Anleitung verwenden möchten, installieren Sie das gcloud-Befehlszeilentool.
Wenn Sie die API-Beispiele in dieser Anleitung verwenden möchten, richten Sie den API-Zugriff ein.
Durch Aufrufen der Methode variables().watch können eine Variable beobachten, um Änderungen festzustellen. Die Methode fragt die Variable 60 Sekunden lang ab und wird wieder aktiviert, wenn sich der Wert der Variable ändert. Wenn sich der Wert innerhalb von 60 Sekunden nicht ändert, wird die Methode beendet und die Variable state=VARIABLE_STATE_UNSPECIFIED zurückgegeben. Wenn die Variable gelöscht wird, gibt die Methode eine Variable state=DELETED und den letzten bekannten Variablenwert zurück.
Zum Festlegen eines Watchers können Sie Deployment Manager, die Google Cloud CLI oder die API verwenden.
Deployment Manager
Dies wird im Deployment Manager nicht unterstützt. Erstellen Sie stattdessen einen Waiter.
[TIMEOUT_SEC] ist die zu wartende Zeit in Sekunden. Der Standard- und Höchstwert beträgt 60 Sekunden.
Die gcloud CLI fragt die Variable ab und wird wieder aktiviert, wenn das festgelegte Zeitlimit erreicht ist oder sich die Variable ändert. Wenn sich die Variable geändert hat, enthält die Antwort einen der anwendbaren Variablenstatus.
API
Erstellen Sie in der API eine POST-Anfrage an den folgenden URI:
[PROJECT_ID] ist die Projekt-ID für diese Anfrage.
[CONFIG_NAME] ist der Name der RuntimeConfig-Ressource für diese Anfrage.
[VARIABLE_KEY] ist der abzufragende Schlüssel.
Optional können Sie mit dem Attribut newerThan eine Anfragenutzlast angeben:
{"newerThan": "[TIMESTAMP]"}
wobei [TIMESTAMP] ein Zeitstempel in RFC 3339 seit der Epoche im UTC-Format "Zulu" ist. Beispiel:
2014-10-02T15:01:23.045123456Z
Bei Angabe des Attributs newerThan gibt die Methode sofort eine Antwort zurück, wenn der aktuelle Zeitstempel für die Variable neuer ist als der angegebene Zeitstempel.
Verwenden Sie das Attribut newerThan, um sicherzustellen, dass Sie keine Änderungen zwischen watch()-Aufrufen verpasst haben.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)."]]