Compare commits
2 Commits
6be508532e
...
eea349af6d
Author | SHA1 | Date | |
---|---|---|---|
|
eea349af6d | ||
|
f48c8a4f4f |
39
.gitea/workflows/ build_check.yaml
Normal file
39
.gitea/workflows/ build_check.yaml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
name: Gitea Build Check
|
||||||
|
run-name: ${{ gitea.actor }} is testing the build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
|
|
||||||
|
- name: Setup Go environment
|
||||||
|
uses: https://github.com/actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
# The Go version to download (if necessary) and use. Supports semver spec and ranges.
|
||||||
|
go-version: 1.22.0 # optional
|
||||||
|
# Path to the go.mod file.
|
||||||
|
go-version-file: ./go.mod # optional
|
||||||
|
# Set this option to true if you want the action to always check for the latest available version that satisfies the version spec
|
||||||
|
check-latest: true # optional
|
||||||
|
# Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
||||||
|
cache: true # optional
|
||||||
|
|
||||||
|
- name: Execute Go Test files with coverage report
|
||||||
|
run: TESTCONTAINERS_RYUK_DISABLED=true go test -v ./... -json -coverprofile="coverage.out" | tee "test-report.out"
|
||||||
|
|
||||||
|
- uses: sonarsource/sonarqube-scan-action@master
|
||||||
|
env:
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
|
||||||
|
with:
|
||||||
|
args: >
|
||||||
|
-Dsonar.projectKey=Anthrove---plug-sdk
|
@ -2,10 +2,11 @@ package plug
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/database"
|
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/database"
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/models"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
"log"
|
|
||||||
|
|
||||||
gRPC "git.dragse.it/anthrove/plug-sdk/pkg/grpc"
|
gRPC "git.dragse.it/anthrove/plug-sdk/pkg/grpc"
|
||||||
gonanoid "github.com/matoous/go-nanoid/v2"
|
gonanoid "github.com/matoous/go-nanoid/v2"
|
||||||
@ -16,13 +17,15 @@ type server struct {
|
|||||||
ctx map[string]context.CancelFunc
|
ctx map[string]context.CancelFunc
|
||||||
database database.OtterSpace
|
database database.OtterSpace
|
||||||
taskExecutionFunction TaskExecution
|
taskExecutionFunction TaskExecution
|
||||||
|
sendMessageExecution SendMessageExecution
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGrpcServer(database database.OtterSpace, taskExecutionFunction TaskExecution) gRPC.PlugConnectorServer {
|
func NewGrpcServer(database database.OtterSpace, taskExecutionFunction TaskExecution, sendMessageExecution SendMessageExecution) gRPC.PlugConnectorServer {
|
||||||
return &server{
|
return &server{
|
||||||
ctx: make(map[string]context.CancelFunc),
|
ctx: make(map[string]context.CancelFunc),
|
||||||
database: database,
|
database: database,
|
||||||
taskExecutionFunction: taskExecutionFunction,
|
taskExecutionFunction: taskExecutionFunction,
|
||||||
|
sendMessageExecution: sendMessageExecution,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +52,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 := s.taskExecutionFunction(ctx, s.database, creation.UserSourceName, anthroveUser, creation.DeepScrape, func() {
|
err := s.taskExecutionFunction(ctx, s.database, creation.UserSourceName, anthroveUser, creation.DeepScrape, creation.ApiKey, func() {
|
||||||
s.removeTask(id)
|
s.removeTask(id)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -101,3 +104,14 @@ func (s *server) Ping(_ context.Context, request *gRPC.PingRequest) (*gRPC.PongR
|
|||||||
}
|
}
|
||||||
return &response, nil
|
return &response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *server) SendMessage(ctx context.Context, request *gRPC.SendMessageRequest) (*gRPC.SendMessageResponse, error) {
|
||||||
|
messageResponse := gRPC.SendMessageResponse{Success: true}
|
||||||
|
|
||||||
|
err := s.sendMessageExecution(ctx, request.UserId, request.Message)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &messageResponse, nil
|
||||||
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TaskExecution func(ctx context.Context, database database.OtterSpace, sourceUsername string, anthroveUser models.User, deepScrape bool, apiKey string, cancelFunction func()) error
|
type TaskExecution func(ctx context.Context, database database.OtterSpace, sourceUsername string, anthroveUser models.User, deepScrape bool, apiKey string, cancelFunction func()) error
|
||||||
type SendMessageExecution func(ctx context.Context, userSourceID string, message string)
|
type SendMessageExecution func(ctx context.Context, userSourceID string, message string) error
|
||||||
|
|
||||||
type Plug struct {
|
type Plug struct {
|
||||||
address string
|
address string
|
||||||
@ -58,7 +58,7 @@ func (p *Plug) Listen() error {
|
|||||||
|
|
||||||
grpcServer := grpc.NewServer()
|
grpcServer := grpc.NewServer()
|
||||||
|
|
||||||
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(p.database, p.taskExecutionFunction))
|
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(p.database, p.taskExecutionFunction, p.sendMessageExecution))
|
||||||
|
|
||||||
err = grpcServer.Serve(lis)
|
err = grpcServer.Serve(lis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user