feat: schedule persistent archive jobs with console management

This commit is contained in:
2026-09-23 11:29:32 +08:00
parent 6eb429e21f
commit 0140c78ea7
32 changed files with 2077 additions and 20 deletions

View File

@@ -13,6 +13,7 @@ import (
"git.yuntuo.hk/k2safe/orbit/internal/config"
"git.yuntuo.hk/k2safe/orbit/internal/observability"
"git.yuntuo.hk/k2safe/orbit/internal/retention"
"git.yuntuo.hk/k2safe/orbit/internal/storage/mysql"
"git.yuntuo.hk/k2safe/orbit/internal/transport/httpserver"
core "git.yuntuo.hk/k2safe/orbit/model"
@@ -123,8 +124,37 @@ func run() error {
httpserver.RegisterWorkflowDefinitions(server, definition.New(mysql.NewWorkflowDefinitionStore(db)))
httpserver.RegisterWorkflows(server, instance.New(mysql.NewWorkflowInstanceStore(db)), control.New(mysql.NewWorkflowControlStore(db)), weavesignal.New(mysql.NewWorkflowSignalStore(db)), recovery.New(mysql.NewWorkflowRecoveryStore(db)))
httpserver.RegisterConsoleRetention(server, consoleAuth, retentionStore, retentionStore)
httpserver.RegisterConsoleArchiveJobs(server, consoleAuth, retentionStore, cfg.ArchiveStorageID)
httpserver.WrapConsoleAuth(server, consoleAuth)
httpserver.WrapMetrics(server, metrics)
if cfg.ArchiveRoot != "" {
archives := &retention.ArchiveRuntime{Directory: cfg.ArchiveRoot, StorageID: cfg.ArchiveStorageID, MaxBytes: cfg.ArchiveMaxBytes, Store: retentionStore}
if err := archives.Init(); err != nil {
return errors.New("archive volume initialization failed; check path, ownership and storage identity")
}
archiveCtx, stopArchives := context.WithCancel(root)
archiveDone := make(chan struct{})
go func() {
defer close(archiveDone)
ticker := time.NewTicker(cfg.ArchiveTickInterval)
defer ticker.Stop()
for {
select {
case <-archiveCtx.Done():
return
case <-ticker.C:
call, cancel := context.WithTimeout(archiveCtx, 45*time.Second)
err := archives.Tick(call)
cancel()
if err != nil && archiveCtx.Err() == nil {
slog.Error("archive batch could not be confirmed", "node_id", node)
}
}
}
}()
defer func() { stopArchives(); <-archiveDone }()
}
workflows, err := mysql.NewWorkflowRuntime(db, node)
if err != nil {
return err