Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
This commit is contained in:
1 parent
9dd425f765
commit
d5d21b7841
302 files changed
+20037
-3492
No files matched your search
@@ -0,0 +1,99 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/dregarnuhr"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
// This adapter preserves SQL/storage ownership and all existing queue IDs.
|
||||
type schedulerQueue struct{ store *store.Store }
|
||||
|
||||
func (q schedulerQueue) Settings(ctx context.Context) (dregarnuhr.Settings, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return dregarnuhr.Settings{}, err
|
||||
}
|
||||
if q.store.ReadOnly || q.store.BackgroundJobsDisabled {
|
||||
return dregarnuhr.Settings{Paused: true}, nil
|
||||
}
|
||||
return q.store.GetQueueSettings()
|
||||
}
|
||||
func (q schedulerQueue) Claim(ctx context.Context, now time.Time) (*dregarnuhr.Job, error) {
|
||||
job, err := q.store.ClaimDueEventAt(ctx, now)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, dregarnuhr.ErrNoJob
|
||||
}
|
||||
return job, err
|
||||
}
|
||||
func (q schedulerQueue) Cancellation(ctx context.Context, id string) (bool, error) {
|
||||
return q.store.EventCancellationState(ctx, id)
|
||||
}
|
||||
func (q schedulerQueue) Started(ctx context.Context, job *dregarnuhr.Job) error {
|
||||
return q.store.AddEventLog(job.UUID, job.EventUUID, "info", "execution started")
|
||||
}
|
||||
func (q schedulerQueue) Finish(ctx context.Context, job *dregarnuhr.Job, err error, now time.Time) error {
|
||||
return q.store.FinishEventAt(ctx, job.UUID, err, now)
|
||||
}
|
||||
|
||||
func (s *Server) eventRunner() *dregarnuhr.Runner {
|
||||
s.schedulerOnce.Do(func() {
|
||||
s.schedulerRunner = dregarnuhr.NewRunner(schedulerQueue{s.store}, s.registeredEventHandlers(), dregarnuhr.RunnerOptions{
|
||||
Active: &s.schedulerRunning,
|
||||
Foreground: func() bool { return s.foregroundRequests.Load() > 0 },
|
||||
Wake: s.wakeEventScheduler,
|
||||
Report: func(stage string, job *dregarnuhr.Job, err error) {
|
||||
if job != nil {
|
||||
log.Printf("component=%s event scheduler %s failed job=%s type=%s: %v", dregarnuhr.Component, stage, job.UUID, job.Type, err)
|
||||
} else {
|
||||
log.Printf("component=%s event scheduler %s failed: %v", dregarnuhr.Component, stage, err)
|
||||
}
|
||||
},
|
||||
})
|
||||
})
|
||||
return s.schedulerRunner
|
||||
}
|
||||
|
||||
func (s *Server) runDueEvents() {
|
||||
if s.store == nil {
|
||||
return
|
||||
}
|
||||
s.eventRunner().Dispatch(context.Background())
|
||||
}
|
||||
|
||||
func (s *Server) schedulerActivity(ctx context.Context, now time.Time) error {
|
||||
_, err := s.store.ExpireApprovalRequests(ctx, now.UnixMilli(), 100)
|
||||
// Preserve independent City processing even if approval expiry fails.
|
||||
s.enqueueCityActivityEvents()
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) schedulerLoop() dregarnuhr.Loop {
|
||||
return dregarnuhr.Loop{
|
||||
Every: time.Second, Wake: s.schedulerWake, OnWake: s.schedulerActivity,
|
||||
Triggers: []dregarnuhr.Trigger{
|
||||
{Name: "initial-preview-sweep", After: 5 * time.Second, Run: func(context.Context, time.Time) error { s.enqueueAllPreviewEvents(); return nil }},
|
||||
{Name: "preview-sweep", Every: 15 * time.Minute, Run: func(context.Context, time.Time) error { s.enqueueAllPreviewEvents(); return nil }},
|
||||
{Name: "history-cleanup", Every: time.Hour, Run: func(context.Context, time.Time) error {
|
||||
settings, err := s.store.GetQueueSettings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.store.PurgeEventHistory(settings.RetentionHours)
|
||||
}},
|
||||
{Name: "activity-sweep", Every: 10 * time.Second, Run: s.schedulerActivity},
|
||||
},
|
||||
Step: func(ctx context.Context, now time.Time) error {
|
||||
_, err := s.store.EnqueueDueDefinitions(now)
|
||||
s.eventRunner().Dispatch(ctx)
|
||||
return err
|
||||
},
|
||||
Report: func(stage string, err error) {
|
||||
log.Printf("component=%s event scheduler %s failed: %v", dregarnuhr.Component, stage, err)
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user