Добавить версии pipeline и защиту от устаревших попыток
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package faults
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -27,3 +29,36 @@ func Crash(point, id string) {
|
||||
os.Exit(86)
|
||||
}
|
||||
}
|
||||
|
||||
// Observe records a test-only branch without exposing an API or a lease token.
|
||||
func Observe(point, id string) {
|
||||
directory := os.Getenv("PIPELINE_FAULT_DIR")
|
||||
if directory == "" {
|
||||
return
|
||||
}
|
||||
if _, err := uuid.Parse(id); err != nil {
|
||||
return
|
||||
}
|
||||
_ = os.WriteFile(filepath.Join(directory, point+"."+id+".observed"), []byte("observed\n"), 0644)
|
||||
}
|
||||
|
||||
// Pause is operator-only and ends on release or context expiry.
|
||||
func Pause(ctx context.Context, point, id string) {
|
||||
if !Take(point, id) {
|
||||
return
|
||||
}
|
||||
release := filepath.Join(os.Getenv("PIPELINE_FAULT_DIR"), point+"."+id+".release")
|
||||
ticker := time.NewTicker(50 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if _, err := os.Stat(release); err == nil {
|
||||
_ = os.WriteFile(release+".observed", []byte("released\n"), 0644)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user