40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"git.cin.su/m/Assistant/adapters/postgres"
|
|
)
|
|
|
|
func main() {
|
|
workerID := flag.String("worker-id", "reflection-worker-1", "stable worker identity")
|
|
lease := flag.Duration("lease-ttl", 5*time.Minute, "candidate claim lease")
|
|
flag.Parse()
|
|
ctx := context.Background()
|
|
config := postgres.ContinuityConfig{Host: os.Getenv("POSTGRES_HOST"), Port: os.Getenv("POSTGRES_PORT"), Database: os.Getenv("POSTGRES_DATABASE"), User: os.Getenv("EPISTEMICS_POSTGRES_USER"), Password: os.Getenv("EPISTEMICS_POSTGRES_PASSWORD")}
|
|
repository, err := postgres.OpenEpistemics(ctx, config)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer repository.Close()
|
|
now := time.Now().UnixMilli()
|
|
if _, err := repository.RecoverReflectionClaims(ctx, now); err != nil {
|
|
panic(err)
|
|
}
|
|
candidate, err := repository.ClaimReflectionCandidate(ctx, *workerID, now, lease.Milliseconds())
|
|
if err != nil {
|
|
fmt.Println("no reflection candidate")
|
|
return
|
|
}
|
|
// This worker only closes the durable evaluation loop. Any cognitive
|
|
// proposal remains a candidate and must be admitted by a separate governed flow.
|
|
if err := repository.ResolveReflectionCandidate(ctx, candidate.ID, *workerID, time.Now().UnixMilli()); err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("resolved reflection candidate %s\n", candidate.ID)
|
|
}
|