labels were the cause I think trying stable again.
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Colin 2024-06-12 20:23:09 -04:00
parent 730ba87306
commit bba46e170b
8 changed files with 11 additions and 51 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

62
main.go
View File

@ -57,24 +57,13 @@ func main() {
log.Fatalf("Error creating diffs directory: %v", err)
}
ticker := time.NewTicker(1 * time.Minute)
defer ticker.Stop()
for {
select {
case <-ticker.C:
log.Println("Fetching and monitoring containers...")
err := fetchAndMonitorContainers()
if err != nil {
log.Printf("Error in fetching and monitoring containers: %v", err)
}
default:
time.Sleep(1 * time.Second)
err := monitorContainers()
if err != nil {
log.Printf("Error in monitoring containers: %v", err)
}
err := fetchAndMonitorContainers()
if err != nil {
log.Printf("Error in fetching and monitoring containers: %v", err)
}
time.Sleep(1 * time.Second)
}
}
@ -83,32 +72,14 @@ func fetchAndMonitorContainers() error {
if err != nil {
return err
}
log.Printf("Fetched %d containers\n", len(containers))
mu.Lock()
defer mu.Unlock()
// Remove containers that are no longer present
for id := range monitoredContainers {
found := false
for _, container := range containers {
if container.ID == id {
found = true
break
}
}
if !found {
delete(monitoredContainers, id)
log.Printf("Stopped monitoring container %s\n", id)
}
}
// Add or update containers
for _, container := range containers {
mu.Lock()
if _, exists := monitoredContainers[container.ID]; !exists {
interval, err := time.ParseDuration(container.Interval)
if err != nil {
log.Printf("Invalid interval for container %s (%s): %v", container.Name, container.ID, err)
mu.Unlock()
continue
}
@ -116,16 +87,10 @@ func fetchAndMonitorContainers() error {
Info: container,
LastChecked: time.Now().Add(-interval),
}
log.Printf("Started monitoring container %s (%s) with interval %s\n", container.Name, container.ID, container.Interval)
} else {
monitoredContainers[container.ID].Info = container
}
mu.Unlock()
}
return nil
}
func monitorContainers() error {
var wg sync.WaitGroup
for _, monitoredContainer := range monitoredContainers {
wg.Add(1)
@ -141,7 +106,6 @@ func monitorContainers() error {
if time.Since(mc.LastChecked) >= interval {
mc.LastChecked = time.Now()
mu.Unlock()
log.Printf("Checking container %s (%s)\n", mc.Info.Name, mc.Info.ID)
checkAndNotify(mc.Info)
} else {
mu.Unlock()
@ -149,6 +113,7 @@ func monitorContainers() error {
}(monitoredContainer)
}
wg.Wait()
return nil
}
@ -246,15 +211,10 @@ func filterDiffOutput(diffOutput, cname string, ignores []string) (string, error
return "", fmt.Errorf("error writing diff to file: %s", err)
}
if len(ignores) == 0 {
log.Println("No ignore patterns provided.")
return "", fmt.Errorf("no ignore patterns provided")
}
// Construct the filter command
args := append([]string{filename}, ignores...)
cmd := exec.Command("/usr/local/bin/oculus_filter", args...)
fullCommand := fmt.Sprintf("oculus_filter %s", strings.Join(cmd.Args, " "))
cmd := exec.Command("filter", args...)
fullCommand := fmt.Sprintf("filter %s", strings.Join(cmd.Args, " "))
log.Printf("Running command: %s", fullCommand)
fmt.Printf("Running command: %s\n", fullCommand) // Print the command to stdout for debugging