chore: refactor
This commit is contained in:
40
app.go
40
app.go
@@ -4,12 +4,10 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"iter"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
_ "embed"
|
||||
|
||||
@@ -18,14 +16,15 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.sour.is/xt/internal/console"
|
||||
"go.sour.is/xt/internal/otel"
|
||||
"go.yarn.social/lextwt"
|
||||
"go.yarn.social/types"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func run(c *console) error {
|
||||
ctx, span := otel.Span(c.Context)
|
||||
func run(ctx context.Context, c *console.C[args]) error {
|
||||
ctx, span := otel.Span(ctx)
|
||||
defer span.End()
|
||||
|
||||
bi, _ := debug.ReadBuildInfo()
|
||||
@@ -33,8 +32,8 @@ func run(c *console) error {
|
||||
|
||||
a := c.Args()
|
||||
app := &appState{
|
||||
args: a,
|
||||
feeds: sync.Map{},
|
||||
args: a,
|
||||
C: c,
|
||||
queue: FibHeap(func(a, b *Feed) bool {
|
||||
return a.NextScanOn.Time.Before(b.NextScanOn.Time)
|
||||
}),
|
||||
@@ -96,25 +95,24 @@ func run(c *console) error {
|
||||
}
|
||||
|
||||
wg, ctx := errgroup.WithContext(ctx)
|
||||
c.Context = ctx
|
||||
|
||||
wg.Go(func() error {
|
||||
return feedRefreshProcessor(c, app)
|
||||
return feedRefreshProcessor(ctx, app)
|
||||
})
|
||||
go httpServer(c, app)
|
||||
go httpServer(ctx, app)
|
||||
|
||||
err = wg.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Context.Err()
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
type appState struct {
|
||||
args args
|
||||
feeds sync.Map
|
||||
queue *fibHeap[Feed]
|
||||
*console.C[args]
|
||||
}
|
||||
|
||||
type db struct {
|
||||
@@ -173,23 +171,3 @@ func (app *appState) DB(ctx context.Context) (db, error) {
|
||||
|
||||
return db, err
|
||||
}
|
||||
|
||||
func (app *appState) Feed(feedID string) *Feed {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *appState) Feeds() iter.Seq2[string, *Feed] {
|
||||
return func(yield func(string, *Feed) bool) {
|
||||
app.feeds.Range(func(k, v any) bool {
|
||||
key, _ := k.(string)
|
||||
value, ok := v.(*Feed)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if !yield(key, value) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user