feat: working implementation of base features
This commit is contained in:
parent
dcb2b2fc68
commit
dea570c55b
3
.gitignore
vendored
3
.gitignore
vendored
@ -191,4 +191,5 @@ $RECYCLE.BIN/
|
||||
/.run/*
|
||||
*.env
|
||||
*pb.go
|
||||
!**/.gitkeep
|
||||
!**/.gitkeep
|
||||
main.go
|
@ -12,14 +12,16 @@ import (
|
||||
|
||||
type server struct {
|
||||
gRPC.UnimplementedPlugConnectorServer
|
||||
ctx map[string]context.CancelFunc
|
||||
database graph.OtterSpace
|
||||
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,
|
||||
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 {
|
||||
|
@ -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
|
||||
database graph.OtterSpace
|
||||
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
0
scripts/generate_grpc_files.sh
Normal file → Executable file
Reference in New Issue
Block a user