This topic describes how to operate a task by using obshell-sdk-go.
Note
We recommend that you read Quick start for a better understanding of how to use obshell-sdk-go.
Considerations
Make sure that OceanBase Shell (obshell) runs normally.
Sample code
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
"github.com/oceanbase/obshell-sdk-go/model"
)
func main() {
var err error // Handle errors in the production environment.
// 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, err := services.NewClientWithPassword("10.10.10.1", 2886, "***")
// Obtain the last O&M task of the current agent.
lastDag, err := c.GetAgentLastMaintenanceDag()
// Roll back the task until it is rolled back successfully.
req := client.V1().NewOperateDagRequest(lastDag.GenericID, model.ROLLBACK_STR)
_, err = client.V1().OperateDagSyncWithRequest(req)
}
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
"github.com/oceanbase/obshell-sdk-go/model"
)
func main() {
var err error // Handle errors in the production environment.
// 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, err := services.NewClientWithPassword("10.10.10.1", 2886, "***")
// Obtain the last O&M task of the current agent.
lastDag, err := c.GetAgentLastMaintenanceDag()
// Roll back the task.
req := client.V1().NewOperateDagRequest(lastDag.GenericID, model.ROLLBACK_STR)
_, err = client.V1().OperateDagWithRequest(req)
}
References
For more information about the API operation, see OperateDag.
For more information about how to call the API operation by using obshell-sdk-python, see Operate a task.