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

1
.gitignore vendored
View File

@ -192,3 +192,4 @@ $RECYCLE.BIN/
*.env
*pb.go
!**/.gitkeep
main.go

View File

@ -14,12 +14,14 @@ type server struct {
gRPC.UnimplementedPlugConnectorServer
ctx map[string]context.CancelFunc
database graph.OtterSpace
taskExecutionFunction TaskExecution
}
func NewGrpcServer(database graph.OtterSpace) gRPC.PlugConnectorServer {
func NewGrpcServer(database graph.OtterSpace, taskExecutionFunction TaskExecution) gRPC.PlugConnectorServer {
return &server{
ctx: make(map[string]context.CancelFunc),
database: database,
taskExecutionFunction: taskExecutionFunction,
}
}
@ -46,7 +48,7 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation)
go func() {
// 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)
})
if err != nil {

View File

@ -3,6 +3,7 @@ package plug
import (
"context"
"fmt"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"net"
"git.dragse.it/anthrove/otter-space-sdk/pkg/graph"
@ -10,11 +11,14 @@ import (
"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 {
ctx context.Context
address string
port string
ctx context.Context
database graph.OtterSpace
taskExecutionFunction TaskExecution
}
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
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()
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(s.database))
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(s.database, s.taskExecutionFunction))
err = grpcServer.Serve(lis)
if err != nil {
@ -45,6 +49,10 @@ func (s Server) Listen() error {
return nil
}
func (s Server) WithGraphConnection(graph graph.OtterSpace) {
func (s *Server) WithGraphConnection(graph graph.OtterSpace) {
s.database = graph
}
func (s *Server) TaskExecutionFunction(function TaskExecution) {
s.taskExecutionFunction = function
}

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