Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
cc cc.CCManager
cipher presign.PreSign
audit *logger.Audit
ctx context.Context

Check failure on line 71 in app/app.go

View workflow job for this annotation

GitHub Actions / Checks / Lint code

found a struct that contains a context.Context field (containedctx)
tracer *Tracer
otelShutdownFunc otelsdk.ShutdownFunc
eventTrigger EventTrigger
Expand Down Expand Up @@ -200,6 +200,7 @@
app.Store = store.NewLayeredStore(sqlSupplier)

app.MessageQueue = rabbit.NewRabbitMQ(app.Config().NodeName, &app.Config().MessageQueueSettings)
app.initDomainEventListener()
app.MessageQueue.Start()

app.Hubs = NewHubs(app)
Expand Down
15 changes: 15 additions & 0 deletions app/online_skills.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import (
"context"

"github.com/webitel/engine/model"
"github.com/webitel/wlog"
)

func (app *App) initDomainEventListener() {
app.MessageQueue.SetDomainsEventHandler(app.handleDomainEventCreated)
}

func (app *App) CreateOnlineSkills(ctx context.Context, preset *model.OnlineSkills) (*model.OnlineSkills, model.AppError) {
preset.PreSave()

Expand Down Expand Up @@ -35,3 +40,13 @@ func (app *App) PatchOnlineSkills(ctx context.Context, cmd *model.PatchOnlineSki
func (app *App) DeleteOnlineSkills(ctx context.Context, cmd *model.DeleteSkillPresetCmd) model.AppError {
return app.Store.OnlineSkills().Delete(ctx, cmd)
}

func (app *App) handleDomainEventCreated(ctx context.Context, e *model.DomainEvent) error {
if err := app.Store.OnlineSkills().CreateSystem(ctx, e.ID); err != nil {
app.Log.Error("processing domain created event", wlog.Err(err))

return err
}

return nil
}
40 changes: 39 additions & 1 deletion model/domain.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
package model

import "time"
import (
"fmt"
"strconv"
"strings"
"time"
)

type DomainEvent struct {
ID int64
}

func NewDomainEventFromRoutingKey(rk string) (*DomainEvent, AppError) {
splitted := strings.Split(rk, ".")
if len(splitted) < 3 {
return nil, NewBadRequestError(
"model.domain.new_domain_event.invalid_rk_len",
"received roting key with len less than 3",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Виправлення друкарської помилки

Suggested change
"received roting key with len less than 3",
"received routing key with len less than 3",

)
}

const domainIdIndex = 2

parsedDomainId, err := strconv.ParseInt(splitted[domainIdIndex], 10, 64)
if err != nil {
return nil, NewBadRequestError(
"model.domain.new_domain_event.parsing_id",
fmt.Sprintf("parsing routing key id to integer: %+v", err),
)
}

if parsedDomainId <= 0 {
return nil, NewBadRequestError(
"model.domain.new_domain_event.domain_id_less_or_equal_zero",
fmt.Sprintf("received domain id less or equal zero: %d", parsedDomainId),
)
}

return &DomainEvent{ID: parsedDomainId}, nil
}

type DomainProvider interface {
Domain(int64) int64
Expand Down
6 changes: 5 additions & 1 deletion mq/layered_mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}

type LayeredMQ struct {
context context.Context

Check failure on line 14 in mq/layered_mq.go

View workflow job for this annotation

GitHub Actions / Checks / Lint code

found a struct that contains a context.Context field (containedctx)
MQLayer LayeredMQLayer
}

Expand Down Expand Up @@ -70,6 +70,10 @@
return l.MQLayer.Send(ctx, exchange, rk, body)
}

func (l *LayeredMQ) SendStartFlow(ctx context.Context, domainId int64, schemaId int32, in interface{}) model.AppError {
func (l *LayeredMQ) SendStartFlow(ctx context.Context, domainId int64, schemaId int32, in any) model.AppError {
return l.MQLayer.SendStartFlow(ctx, domainId, schemaId, in)
}

func (l *LayeredMQ) SetDomainsEventHandler(h DomainEventHandler) {
l.MQLayer.SetDomainsEventHandler(h)
}
4 changes: 4 additions & 0 deletions mq/mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package mq

import (
"context"

"github.com/webitel/engine/model"
)

type DomainEventHandler func(ctx context.Context, e *model.DomainEvent) error

type MQ interface {
SendJSON(name string, data []byte) model.AppError
BindCallEvents(domainId, userId int64) error
Expand All @@ -25,6 +28,7 @@ type MQ interface {
Send(ctx context.Context, exchange string, rk string, body []byte) error

SendStartFlow(ctx context.Context, domainId int64, schemaId int32, in interface{}) model.AppError
SetDomainsEventHandler(h DomainEventHandler)
}

type DomainQueue interface {
Expand Down
Loading
Loading