Compare commits

..

2 Commits

Author SHA1 Message Date
David Janowski
eea349af6d ci: added build check 2024-07-08 15:07:48 +02:00
David Janowski
f48c8a4f4f feat: implemented the new Message Function 2024-07-08 14:56:17 +02:00
3 changed files with 58 additions and 5 deletions

View 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

View File

@ -2,10 +2,11 @@ package plug
import (
"context"
"log"
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/database"
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/models"
"google.golang.org/protobuf/types/known/timestamppb"
"log"
gRPC "git.dragse.it/anthrove/plug-sdk/pkg/grpc"
gonanoid "github.com/matoous/go-nanoid/v2"
@ -16,13 +17,15 @@ type server struct {
ctx map[string]context.CancelFunc
database database.OtterSpace
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{
ctx: make(map[string]context.CancelFunc),
database: database,
taskExecutionFunction: taskExecutionFunction,
sendMessageExecution: sendMessageExecution,
}
}
@ -49,7 +52,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 := 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)
})
if err != nil {
@ -101,3 +104,14 @@ func (s *server) Ping(_ context.Context, request *gRPC.PingRequest) (*gRPC.PongR
}
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
}

View File

@ -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 SendMessageExecution func(ctx context.Context, userSourceID string, message string)
type SendMessageExecution func(ctx context.Context, userSourceID string, message string) error
type Plug struct {
address string
@ -58,7 +58,7 @@ func (p *Plug) Listen() error {
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)
if err != nil {