This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/schedulers/states.go
2018-10-06 20:03:14 -07:00

64 lines
1.8 KiB
Go

// Copyright (C) 2018 spdf
//
// This file is part of Elektron.
//
// Elektron is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Elektron is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Elektron. If not, see <http://www.gnu.org/licenses/>.
//
package schedulers
import (
"fmt"
mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
)
// NameFor returns the string name for a TaskState.
func NameFor(state *mesos.TaskState) string {
switch *state {
case mesos.TaskState_TASK_STAGING:
return "TASK_STAGING"
case mesos.TaskState_TASK_STARTING:
return "TASK_STARTING"
case mesos.TaskState_TASK_RUNNING:
return "TASK_RUNNING"
case mesos.TaskState_TASK_FINISHED:
return "TASK_FINISHED" // TERMINAL
case mesos.TaskState_TASK_FAILED:
return "TASK_FAILED" // TERMINAL
case mesos.TaskState_TASK_KILLED:
return "TASK_KILLED" // TERMINAL
case mesos.TaskState_TASK_LOST:
return "TASK_LOST" // TERMINAL
case mesos.TaskState_TASK_ERROR:
return "TASK_ERROR"
default:
return fmt.Sprintf("UNKNOWN: %d", *state)
}
}
// IsTerminal determines if a TaskState is a terminal state, i.e. if it singals
// that the task has stopped running.
func IsTerminal(state *mesos.TaskState) bool {
switch *state {
case mesos.TaskState_TASK_FINISHED,
mesos.TaskState_TASK_FAILED,
mesos.TaskState_TASK_KILLED,
mesos.TaskState_TASK_LOST,
mesos.TaskState_TASK_ERROR:
return true
default:
return false
}
}