feat: working implementation of base features

This commit is contained in:
SoXX 2024-02-20 21:12:49 +01:00
parent dcb2b2fc68
commit dea570c55b
4 changed files with 25 additions and 14 deletions

3
.gitignore vendored
View File

@ -191,4 +191,5 @@ $RECYCLE.BIN/
/.run/* /.run/*
*.env *.env
*pb.go *pb.go
!**/.gitkeep !**/.gitkeep
main.go

View File

@ -12,14 +12,16 @@ import (
type server struct { type server struct {
gRPC.UnimplementedPlugConnectorServer gRPC.UnimplementedPlugConnectorServer
ctx map[string]context.CancelFunc ctx map[string]context.CancelFunc
database graph.OtterSpace database graph.OtterSpace
taskExecutionFunction TaskExecution
} }
func NewGrpcServer(database graph.OtterSpace) gRPC.PlugConnectorServer { func NewGrpcServer(database graph.OtterSpace, taskExecutionFunction TaskExecution) gRPC.PlugConnectorServer {
return &server{ return &server{
ctx: make(map[string]context.CancelFunc), ctx: make(map[string]context.CancelFunc),
database: database, database: database,
taskExecutionFunction: taskExecutionFunction,
} }
} }
@ -46,7 +48,7 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
go func() { go func() {
// FIXME: better implement this methode, works for now but needs refactoring // FIXME: better implement this methode, works for now but needs refactoring
err := service.ScrapeUser(ctx, s.database, &s.e621Client, creation.UserSourceName, &anthroveUser, creation.DeepScrape, func() { err := s.taskExecutionFunction(ctx, s.database, creation.UserSourceName, anthroveUser, creation.DeepScrape, func() {
s.removeTask(id) s.removeTask(id)
}) })
if err != nil { if err != nil {

View File

@ -3,6 +3,7 @@ package plug
import ( import (
"context" "context"
"fmt" "fmt"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"net" "net"
"git.dragse.it/anthrove/otter-space-sdk/pkg/graph" "git.dragse.it/anthrove/otter-space-sdk/pkg/graph"
@ -10,11 +11,14 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
type TaskExecution func(ctx context.Context, graph graph.OtterSpace, sourceUsername string, anthroveUser models.AnthroveUser, deepScrape bool, cancelFunction func()) error
type Server struct { type Server struct {
ctx context.Context address string
address string port string
port string ctx context.Context
database graph.OtterSpace database graph.OtterSpace
taskExecutionFunction TaskExecution
} }
func NewServer(ctx context.Context, address string, port string) Server { func NewServer(ctx context.Context, address string, port string) Server {
@ -25,7 +29,7 @@ func NewServer(ctx context.Context, address string, port string) Server {
} }
} }
func (s Server) Listen() error { func (s *Server) Listen() error {
var err error var err error
lis, err := net.Listen("tcp", fmt.Sprintf("%s:%s", s.address, s.port)) lis, err := net.Listen("tcp", fmt.Sprintf("%s:%s", s.address, s.port))
@ -35,7 +39,7 @@ func (s Server) Listen() error {
grpcServer := grpc.NewServer() grpcServer := grpc.NewServer()
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(s.database)) pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(s.database, s.taskExecutionFunction))
err = grpcServer.Serve(lis) err = grpcServer.Serve(lis)
if err != nil { if err != nil {
@ -45,6 +49,10 @@ func (s Server) Listen() error {
return nil return nil
} }
func (s Server) WithGraphConnection(graph graph.OtterSpace) { func (s *Server) WithGraphConnection(graph graph.OtterSpace) {
s.database = graph s.database = graph
} }
func (s *Server) TaskExecutionFunction(function TaskExecution) {
s.taskExecutionFunction = function
}

0
scripts/generate_grpc_files.sh Normal file → Executable file
View File