Lang andauernde Vorgänge abrufen

Einige Methoden geben einen Vorgang mit langer Ausführungszeit zurück. Lang andauernde Methoden sind asynchron und der Vorgang ist möglicherweise noch nicht abgeschlossen, wenn die Methode eine Antwort zurückgibt. Sie können den Vorgang abfragen, um seinen Status zu prüfen.

Vorgangsstatus abrufen

Im Folgenden wird gezeigt, wie Sie den Status eines Vorgangs abrufen, indem Sie die Methode get für die Ressource Operation aufrufen.

REST

Ausführliche Informationen finden Sie unter dem API-Endpunkt operations:get. Wenn der Vorgang abgeschlossen ist, wird ein state-Wert von SUCCESSFUL zurückgegeben. Das folgende Beispiel zeigt die erwartete JSON-Ausgabe nach Abschluss eines CreateIssueModel-Vorgangs. Die Ausgabe kann je nach API, die den Vorgang ausgeführt hat, variieren.

Ersetzen Sie diese Werte in den folgenden Anfragedaten:

  • PROJECT_ID: Projekt-ID in Google Cloud .
  • OPERATION_ID: die ID der Unterhaltung, die Sie analysieren möchten. Dieser Wert wurde zurückgegeben, als Sie die Analyse erstellt haben.

HTTP-Methode und URL:

GET https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID

Wenn Sie die Anfrage senden möchten, maximieren Sie eine der folgenden Optionen:

Sie sollten eine JSON-Antwort ähnlich wie diese erhalten:

{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.contactcenterinsights.v1.CreateIssueModelMetadata",
    "createTime": "2021-01-20T10:10:10.123000Z",
    "endTime": "2021-01-20T11:11:11.456000Z",
    "request": {
      "parent": "projects/PROJECT_ID/locations/us-central1",
      "issueModel": {
        "displayName": "MODEL_NAME",
        "inputDataConfig": {
          "medium": "CHAT",
          "trainingConversationsCount": "12000",
          "filter": "medium=\"CHAT\""
        }
      }
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.contactcenterinsights.v1.IssueModel",
    "name": "projects/PROJECT_ID/locations/us-central1/issueModels/ISSUE_MODEL_ID",
    "displayName": "my-model",
    "createTime": "2021-01-20T11:11:11.456000Z",
    "state": "UNDEPLOYED",
    "inputDataConfig": {
      "medium": "CHAT",
      "trainingConversationsCount": "12000",
      "filter": "medium=\"CHAT\""
    },
    "trainingStats": {
      "analyzedConversationsCount": "8000",
      "issueStats": {
        "projects/PROJECT_ID/locations/us-central1/issueModels/ISSUE_MODEL_ID/issues/123000": {
          "issue": "projects/$PROJECT/locations/us-central1/issueModels/ISSUE_MODEL_ID/issues/123000",
          "labeledConversationsCount": "10"
        },
        "projects/PROJECT_ID/locations/us-central1/issueModels/ISSUE_MODEL_ID/issues/456000": {
          "issue": "projects/$PROJECT/locations/us-central1/issueModels/ISSUE_MODEL_IDL/issues/456000",
          "labeledConversationsCount": "20"
        },
        ...
      }
    }
  }
}

Python

Richten Sie zur Authentifizierung bei CX Insights die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

from google.cloud import contact_center_insights_v1
from google.longrunning import operations_pb2


def get_operation(operation_name: str) -> operations_pb2.Operation:
    """Gets an operation.

    Args:
        operation_name:
            The operation name.
            Format is 'projects/{project_id}/locations/{location_id}/operations/{operation_id}'.
            For example, 'projects/my-project/locations/us-central1/operations/123456789'.

    Returns:
        An operation.
    """
    # Construct an Insights client that will authenticate via Application Default Credentials.
    # See authentication details at https://cloud.google.com/docs/authentication/production.
    insights_client = contact_center_insights_v1.ContactCenterInsightsClient()

    # Call the Insights client to get the operation.
    operation = insights_client.transport.operations_client.get_operation(
        operation_name
    )
    if operation.done:
        print("Operation is done")
    else:
        print("Operation is in progress")

Java

Richten Sie zur Authentifizierung bei CX Insights die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


import com.google.cloud.contactcenterinsights.v1.ContactCenterInsightsClient;
import com.google.longrunning.Operation;
import com.google.longrunning.OperationsClient;
import java.io.IOException;

public class GetOperation {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace this variable before running the sample.
    String operationName = "projects/my_project_id/locations/us-central1/operations/12345";

    getOperation(operationName);
  }

  public static Operation getOperation(String operationName) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ContactCenterInsightsClient client = ContactCenterInsightsClient.create()) {
      OperationsClient operationsClient = client.getOperationsClient();
      Operation operation = operationsClient.getOperation(operationName);

      System.out.printf("Got operation %s%n", operation.getName());
      return operation;
    }
  }
}

Node.js

Richten Sie zur Authentifizierung bei CX Insights die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

/**
 * TODO(developer): Uncomment this variable before running the sample.
 */
// const operationName = 'projects/my_project_id/locations/us-central1/operations/my_operation_id';

// Imports the Contact Center Insights client.
const {
  ContactCenterInsightsClient,
} = require('@google-cloud/contact-center-insights');

// Instantiates a client.
const client = new ContactCenterInsightsClient();

async function getOperation() {
  const [operation] = await client.operationsClient.getOperation({
    name: operationName,
  });
  console.info(`Got operation ${operation.name}.`);
}
getOperation();