Semaphore/lib/Logger.go

54 lines
1.2 KiB
Go
Raw Normal View History

package lib
import (
"os/exec"
"strings"
"time"
)
2023-09-23 17:12:35 +02:00
type TaskStatus string
const (
2024-01-30 13:47:03 +01:00
TaskWaitingStatus TaskStatus = "waiting"
TaskStartingStatus TaskStatus = "starting"
TaskWaitingConfirmation TaskStatus = "waiting_confirmation"
TaskConfirmed TaskStatus = "confirmed"
TaskRunningStatus TaskStatus = "running"
TaskStoppingStatus TaskStatus = "stopping"
TaskStoppedStatus TaskStatus = "stopped"
TaskSuccessStatus TaskStatus = "success"
TaskFailStatus TaskStatus = "error"
2023-09-23 17:12:35 +02:00
)
func (s TaskStatus) IsNotifiable() bool {
return s == TaskSuccessStatus || s == TaskFailStatus || s == TaskWaitingConfirmation
}
func (s TaskStatus) Format() (res string) {
switch s {
case TaskFailStatus:
res += "❌"
case TaskSuccessStatus:
res += "✅"
case TaskStoppedStatus:
res += "⏹️"
case TaskWaitingConfirmation:
res += "⚠️"
}
res += strings.ToUpper(string(s))
return
}
2023-09-23 17:12:35 +02:00
func (s TaskStatus) IsFinished() bool {
return s == TaskStoppedStatus || s == TaskSuccessStatus || s == TaskFailStatus
}
type Logger interface {
Log(msg string)
Log2(msg string, now time.Time)
LogCmd(cmd *exec.Cmd)
2023-09-23 17:12:35 +02:00
SetStatus(status TaskStatus)
}