This topic describes how to operate a task by using obshell-sdk-python.
Note
We recommend that you read Quick start for a better understanding of how to use obshell-sdk-python.
Considerations
Make sure that OceanBase Shell (obshell) runs normally.
Sample code
from obshell import ClientSet
from obshell.auth import PasswordAuth
# Create a client instance, with the IP address of "10.10.10.1" and the port number of 2886.
# Enter the root@sys password "****" for the cluster.
client = ClientSet("10.10.10.1", 2886, PasswordAuth("****"))
try:
# Initialize the cluster.
client.v1.init_sync()
except cli.TaskExecuteFailedError as e: # Capture the exception during the execution of the cluster initialization task.
client.v1.operate_dag_sync(e.dag.generic_id, "ROLLBACK") # Roll back the task.
from obshell import ClientSet
from obshell.auth import PasswordAuth
# Create a client instance, with the IP address of "10.10.10.1" and the port number of 2886.
# Enter the root@sys password "****" for the cluster.
client = ClientSet("10.10.10.1", 2886, PasswordAuth("****"))
try:
# Initialize the cluster.
client.v1.init_sync()
except cli.TaskExecuteFailedError as e: # Capture the exception during the execution of the cluster initialization task.
client.v1.operate_dag(e.dag.generic_id, "ROLLBACK") # Roll back the task.
References
For more information about the API operation, see OperateDag.
For more information about how to call the API operation by using obshell-sdk-go, see Operate a task.