41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package execute
|
|
|
|
import "strings"
|
|
|
|
// ResultTier implements tools.TierClassifier. It reads the tool script's
|
|
// "ollie:tier" annotation to determine result retention. Returns "hot" if
|
|
// no annotation is found.
|
|
func (e *Server) ResultTier(name string) string {
|
|
code, err := ReadTool(name)
|
|
if err != nil {
|
|
return "hot"
|
|
}
|
|
return detectTier(code)
|
|
}
|
|
|
|
// detectTier scans the first 10 lines of a tool script for an
|
|
// "ollie:tier" annotation. Matches "ollie:tier hot", "ollie:tier warm",
|
|
// or "ollie:tier cold" anywhere in the line.
|
|
func detectTier(code string) string {
|
|
lines := strings.SplitN(code, "\n", 11)
|
|
if len(lines) > 10 {
|
|
lines = lines[:10]
|
|
}
|
|
for _, line := range lines {
|
|
idx := strings.Index(line, "ollie:tier")
|
|
if idx < 0 {
|
|
continue
|
|
}
|
|
rest := strings.TrimSpace(line[idx+len("ollie:tier"):])
|
|
switch {
|
|
case rest == "cold" || strings.HasPrefix(rest, "cold "):
|
|
return "cold"
|
|
case rest == "warm" || strings.HasPrefix(rest, "warm "):
|
|
return "warm"
|
|
case rest == "hot" || strings.HasPrefix(rest, "hot "):
|
|
return "hot"
|
|
}
|
|
}
|
|
return "hot"
|
|
}
|