Skip to content
gojuukaze edited this page Aug 27, 2022 · 1 revision

abort task

abort not running tasks

The second parameter is the expiration time of the abort mark. If there are too many tasks, it is recommended to set it longer, or set it to -1, and then manually clean it up.

(For mongo, setting the expiration time here is invalid, it can only be set at NewBackend)

client.AbortTask(id, 10)

abort a running task

For running tasks, you also need to call AbortTask() to set the abort flag. Then manually detect in the task function, and abort.

func abortWorker(ctl *server.TaskCtl, a int) int {
    // do ...

    if f, _ := ctl.IsAbort(); f {
        ctl.Abort("Abort")
        // don't forget return
        return 0
    }

    return a * a

then

client.AbortTask(id, 10)