[wip] daemon separation

This commit is contained in:
royalcat 2024-11-24 20:33:44 +03:00
parent 98ee1dc6f1
commit fa084118c3
48 changed files with 48 additions and 35 deletions

View file

@ -27,11 +27,11 @@ models:
Torrent:
extraFields:
T:
type: "*git.kmsign.ru/royalcat/tstor/src/daemons/torrent.Controller"
type: "*git.kmsign.ru/royalcat/tstor/daemons/torrent.Controller"
TorrentFile:
extraFields:
F:
type: "*git.kmsign.ru/royalcat/tstor/src/daemons/torrent.FileController"
type: "*git.kmsign.ru/royalcat/tstor/daemons/torrent.FileController"
TorrentPeer:
extraFields:
F:
@ -45,7 +45,7 @@ models:
TorrentFS:
extraFields:
FS:
type: "*git.kmsign.ru/royalcat/tstor/src/daemons/torrent.TorrentFS"
type: "*git.kmsign.ru/royalcat/tstor/daemons/torrent.TorrentFS"
ResolverFS:
extraFields:
FS:

View file

@ -6,6 +6,7 @@ COPY go.mod ./
COPY go.sum ./
RUN --mount=type=cache,mode=0777,target=/go/pkg/mod go mod download all
COPY ./daemons ./daemons
COPY ./pkg ./pkg
COPY ./src ./src
COPY ./cmd ./cmd

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/fs"
"log/slog"
"net"
@ -13,13 +14,13 @@ import (
"os/signal"
"syscall"
"git.kmsign.ru/royalcat/tstor/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/daemons/ytdlp"
"git.kmsign.ru/royalcat/tstor/pkg/ctxbilly"
wnfs "git.kmsign.ru/royalcat/tstor/pkg/go-nfs"
"git.kmsign.ru/royalcat/tstor/pkg/rlog"
"git.kmsign.ru/royalcat/tstor/src/config"
"git.kmsign.ru/royalcat/tstor/src/daemons"
"git.kmsign.ru/royalcat/tstor/src/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/src/daemons/ytdlp"
"git.kmsign.ru/royalcat/tstor/src/delivery"
"git.kmsign.ru/royalcat/tstor/src/telemetry"
"git.kmsign.ru/royalcat/tstor/src/vfs"
@ -118,6 +119,10 @@ func run(configPath string) error {
return err
}
vfs.Walk(ctx, sfs, "/", func(path string, info fs.FileInfo, err error) error {
return nil
})
if conf.Mounts.Fuse.Enabled {
mh := fuse.NewHandler(conf.Mounts.Fuse.AllowOther, conf.Mounts.Fuse.Path)
err := mh.Mount(sfs)

View file

@ -12,7 +12,7 @@ import (
"git.kmsign.ru/royalcat/tstor/pkg/rlog"
)
func (d *Daemon) Cleanup(ctx context.Context, dryRun bool) ([]string, error) {
func (d *Daemon) Cleanup(ctx context.Context, run bool) ([]string, error) {
d.log.Info(ctx, "cleanup started")
torrentInfos, err := d.client.qb.Torrent().GetTorrents(ctx, &qbittorrent.TorrentOption{})
@ -37,7 +37,7 @@ func (d *Daemon) Cleanup(ctx context.Context, dryRun bool) ([]string, error) {
slog.Any("infohashes", torrentToDelete),
)
if dryRun {
if !run {
d.log.Info(ctx, "dry run, skipping deletion")
return torrentToDelete, nil
}

View file

@ -26,7 +26,7 @@ import (
"go.opentelemetry.io/otel"
)
var trace = otel.Tracer("git.kmsign.ru/royalcat/tstor/src/daemons/qbittorrent")
var trace = otel.Tracer("git.kmsign.ru/royalcat/tstor/daemons/qbittorrent")
type Daemon struct {
proc *os.Process
@ -231,6 +231,9 @@ func (d *Daemon) syncTorrentState(ctx context.Context, file vfs.File, ih metainf
if err == nil {
break
}
if errors.Is(err, context.DeadlineExceeded) {
return err
}
log.Error(ctx, "waiting for torrent to be added", rlog.Error(err))
time.Sleep(time.Millisecond * 15)
}

View file

@ -1,5 +1,5 @@
type QBitTorrentDaemonMutation {
cleanup(dryRun: Boolean!): QBitCleanupResponse! @resolver
cleanup(run: Boolean!): QBitCleanupResponse! @resolver
}
type QBitCleanupResponse {

View file

@ -3,8 +3,8 @@ package daemons
import (
"context"
"git.kmsign.ru/royalcat/tstor/src/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/src/daemons/ytdlp"
"git.kmsign.ru/royalcat/tstor/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/daemons/ytdlp"
"git.kmsign.ru/royalcat/tstor/src/vfs"
)

View file

@ -92,7 +92,7 @@ type ComplexityRoot struct {
}
QBitTorrentDaemonMutation struct {
Cleanup func(childComplexity int, dryRun bool) int
Cleanup func(childComplexity int, run bool) int
}
QBitTorrentDaemonQuery struct {
@ -233,7 +233,7 @@ type MutationResolver interface {
DedupeStorage(ctx context.Context) (int64, error)
}
type QBitTorrentDaemonMutationResolver interface {
Cleanup(ctx context.Context, obj *model.QBitTorrentDaemonMutation, dryRun bool) (*model.QBitCleanupResponse, error)
Cleanup(ctx context.Context, obj *model.QBitTorrentDaemonMutation, run bool) (*model.QBitCleanupResponse, error)
}
type QBitTorrentDaemonQueryResolver interface {
Torrents(ctx context.Context, obj *model.QBitTorrentDaemonQuery) ([]*model.QTorrent, error)
@ -398,7 +398,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
return e.complexity.QBitTorrentDaemonMutation.Cleanup(childComplexity, args["dryRun"].(bool)), true
return e.complexity.QBitTorrentDaemonMutation.Cleanup(childComplexity, args["run"].(bool)), true
case "QBitTorrentDaemonQuery.torrents":
if e.complexity.QBitTorrentDaemonQuery.Torrents == nil {
@ -1105,7 +1105,7 @@ interface Progress {
total: Int!
}`, BuiltIn: false},
{Name: "../../../graphql/sources/qbittorrent_mutation.graphql", Input: `type QBitTorrentDaemonMutation {
cleanup(dryRun: Boolean!): QBitCleanupResponse! @resolver
cleanup(run: Boolean!): QBitCleanupResponse! @resolver
}
type QBitCleanupResponse {
@ -1384,28 +1384,28 @@ func (ec *executionContext) field_Mutation_uploadFile_argsFile(
func (ec *executionContext) field_QBitTorrentDaemonMutation_cleanup_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
arg0, err := ec.field_QBitTorrentDaemonMutation_cleanup_argsDryRun(ctx, rawArgs)
arg0, err := ec.field_QBitTorrentDaemonMutation_cleanup_argsRun(ctx, rawArgs)
if err != nil {
return nil, err
}
args["dryRun"] = arg0
args["run"] = arg0
return args, nil
}
func (ec *executionContext) field_QBitTorrentDaemonMutation_cleanup_argsDryRun(
func (ec *executionContext) field_QBitTorrentDaemonMutation_cleanup_argsRun(
ctx context.Context,
rawArgs map[string]interface{},
) (bool, error) {
// We won't call the directive if the argument is null.
// Set call_argument_directives_with_null to true to call directives
// even if the argument is null.
_, ok := rawArgs["dryRun"]
_, ok := rawArgs["run"]
if !ok {
var zeroVal bool
return zeroVal, nil
}
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("dryRun"))
if tmp, ok := rawArgs["dryRun"]; ok {
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("run"))
if tmp, ok := rawArgs["run"]; ok {
return ec.unmarshalNBoolean2bool(ctx, tmp)
}
@ -2476,7 +2476,7 @@ func (ec *executionContext) _QBitTorrentDaemonMutation_cleanup(ctx context.Conte
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
directive0 := func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.QBitTorrentDaemonMutation().Cleanup(rctx, obj, fc.Args["dryRun"].(bool))
return ec.resolvers.QBitTorrentDaemonMutation().Cleanup(rctx, obj, fc.Args["run"].(bool))
}
directive1 := func(ctx context.Context) (interface{}, error) {

View file

@ -3,7 +3,7 @@ package model
import (
"context"
"git.kmsign.ru/royalcat/tstor/src/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/src/vfs"
)

View file

@ -3,7 +3,7 @@ package model
import (
"context"
"git.kmsign.ru/royalcat/tstor/src/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/daemons/torrent"
atorrent "github.com/anacrolix/torrent"
)

View file

@ -5,7 +5,7 @@ package model
import (
"time"
"git.kmsign.ru/royalcat/tstor/src/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/src/vfs"
torrent1 "github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/types"

View file

@ -12,8 +12,8 @@ import (
)
// Cleanup is the resolver for the cleanup field.
func (r *qBitTorrentDaemonMutationResolver) Cleanup(ctx context.Context, obj *model.QBitTorrentDaemonMutation, dryRun bool) (*model.QBitCleanupResponse, error) {
hahses, err := r.QBitTorrentDaemon.Cleanup(ctx, dryRun)
func (r *qBitTorrentDaemonMutationResolver) Cleanup(ctx context.Context, obj *model.QBitTorrentDaemonMutation, run bool) (*model.QBitCleanupResponse, error) {
hahses, err := r.QBitTorrentDaemon.Cleanup(ctx, run)
if err != nil {
return nil, err
}

View file

@ -1,8 +1,8 @@
package resolver
import (
"git.kmsign.ru/royalcat/tstor/src/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/src/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/src/vfs"
"github.com/go-git/go-billy/v5"
)

View file

@ -10,7 +10,7 @@ import (
"strings"
"time"
"git.kmsign.ru/royalcat/tstor/src/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/daemons/torrent"
graph "git.kmsign.ru/royalcat/tstor/src/delivery/graphql"
"git.kmsign.ru/royalcat/tstor/src/delivery/graphql/model"
tinfohash "github.com/anacrolix/torrent/types/infohash"

View file

@ -5,10 +5,10 @@ import (
"log/slog"
"net/http"
"git.kmsign.ru/royalcat/tstor/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/pkg/rlog"
"git.kmsign.ru/royalcat/tstor/src/config"
"git.kmsign.ru/royalcat/tstor/src/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/src/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/src/vfs"
echopprof "github.com/labstack/echo-contrib/pprof"
"github.com/labstack/echo/v4"

View file

@ -4,8 +4,8 @@ import (
"context"
"net/http"
"git.kmsign.ru/royalcat/tstor/src/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/src/daemons/torrent"
"git.kmsign.ru/royalcat/tstor/daemons/qbittorrent"
"git.kmsign.ru/royalcat/tstor/daemons/torrent"
graph "git.kmsign.ru/royalcat/tstor/src/delivery/graphql"
"git.kmsign.ru/royalcat/tstor/src/delivery/graphql/resolver"
"git.kmsign.ru/royalcat/tstor/src/vfs"

View file

@ -57,8 +57,12 @@ interface Progress {
current: Int!
total: Int!
}
type QBitCleanupResponse {
count: Int!
hashes: [String!]!
}
type QBitTorrentDaemonMutation {
cleanup(dryRun: Boolean!): Int! @resolver
cleanup(run: Boolean!): QBitCleanupResponse! @resolver
}
type QBitTorrentDaemonQuery {
torrents: [QTorrent!]! @resolver