snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
38
server/pkg/messagebus/consumer/eventbus.go
Normal file
38
server/pkg/messagebus/consumer/eventbus.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package consumer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/eventbus"
|
||||
"github.com/cortezaproject/corteza/server/pkg/messagebus/types"
|
||||
)
|
||||
|
||||
type (
|
||||
Dispatcher interface {
|
||||
Dispatch(ctx context.Context, ev eventbus.Event)
|
||||
WaitFor(ctx context.Context, ev eventbus.Event) (err error)
|
||||
}
|
||||
|
||||
EventbusConsumer struct {
|
||||
queue string
|
||||
handle types.ConsumerType
|
||||
dispatcher Dispatcher
|
||||
servicer types.QueueEventBuilder
|
||||
}
|
||||
)
|
||||
|
||||
func NewEventbusConsumer(q string, servicer types.QueueEventBuilder) *EventbusConsumer {
|
||||
h := &EventbusConsumer{
|
||||
queue: q,
|
||||
handle: types.ConsumerEventbus,
|
||||
dispatcher: eventbus.Service(),
|
||||
servicer: servicer,
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (cq *EventbusConsumer) Write(ctx context.Context, p []byte) error {
|
||||
cq.dispatcher.Dispatch(ctx, cq.servicer.CreateQueueEvent(cq.queue, p))
|
||||
return nil
|
||||
}
|
||||
40
server/pkg/messagebus/consumer/store.go
Normal file
40
server/pkg/messagebus/consumer/store.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package consumer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/messagebus/store"
|
||||
"github.com/cortezaproject/corteza/server/pkg/messagebus/types"
|
||||
)
|
||||
|
||||
type (
|
||||
StoreConsumer struct {
|
||||
queue string
|
||||
handle types.ConsumerType
|
||||
client store.StoreClient
|
||||
poll *time.Ticker
|
||||
}
|
||||
)
|
||||
|
||||
func NewStoreConsumer(q string, s types.QueueServicer) *StoreConsumer {
|
||||
h := &StoreConsumer{
|
||||
queue: q,
|
||||
handle: types.ConsumerStore,
|
||||
client: store.NewClient(s),
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (cq *StoreConsumer) Write(ctx context.Context, p []byte) error {
|
||||
return cq.client.Add(ctx, cq.queue, p)
|
||||
}
|
||||
|
||||
func (cq *StoreConsumer) SetStore(s types.QueueStorer) {
|
||||
cq.client.SetStore(s)
|
||||
}
|
||||
|
||||
func (cq *StoreConsumer) GetStore() types.QueueStorer {
|
||||
return cq.client.GetStore()
|
||||
}
|
||||
94
server/pkg/messagebus/consumer/store_test.go
Normal file
94
server/pkg/messagebus/consumer/store_test.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package consumer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/messagebus/store"
|
||||
"github.com/cortezaproject/corteza/server/pkg/messagebus/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type (
|
||||
mockClient struct {
|
||||
add func(context.Context, string, []byte) (err error)
|
||||
process func(context.Context, uint64, types.QueueMessage) (err error)
|
||||
|
||||
setStore func(types.QueueStorer)
|
||||
getStore func() types.QueueStorer
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
successfulClient = mockClient{
|
||||
add: func(c context.Context, q string, p []byte) error {
|
||||
return nil
|
||||
},
|
||||
process: func(c context.Context, u uint64, qm types.QueueMessage) (err error) { return },
|
||||
}
|
||||
|
||||
unsuccessfulClient = mockClient{
|
||||
add: func(c context.Context, q string, p []byte) error {
|
||||
return fmt.Errorf("could not write messages")
|
||||
},
|
||||
process: func(c context.Context, u uint64, qm types.QueueMessage) (err error) {
|
||||
return fmt.Errorf("could not process messages")
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func Test_handlerSqlWrite(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
tcc = []struct {
|
||||
name string
|
||||
err error
|
||||
payload []byte
|
||||
client store.StoreClient
|
||||
}{
|
||||
{
|
||||
name: "write success",
|
||||
err: nil,
|
||||
client: &successfulClient,
|
||||
},
|
||||
{
|
||||
name: "write error",
|
||||
err: fmt.Errorf("could not write messages"),
|
||||
client: &unsuccessfulClient,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
h := StoreConsumer{queue: "foobar", handle: types.ConsumerStore, client: tc.client}
|
||||
|
||||
err := h.Write(ctx, []byte("foo bar"))
|
||||
|
||||
req.Equal(tc.err, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (mc *mockClient) Add(ctx context.Context, q string, p []byte) error {
|
||||
return mc.add(ctx, q, p)
|
||||
}
|
||||
|
||||
func (mc *mockClient) Process(ctx context.Context, ID uint64, m types.QueueMessage) error {
|
||||
return mc.process(ctx, ID, m)
|
||||
}
|
||||
|
||||
func (mc *mockClient) GetStore() types.QueueStorer {
|
||||
return mc.getStore()
|
||||
}
|
||||
|
||||
func (mc *mockClient) SetStore(s types.QueueStorer) {
|
||||
mc.setStore(s)
|
||||
}
|
||||
|
||||
func makeDelay(d time.Duration) *time.Duration {
|
||||
return &d
|
||||
}
|
||||
Reference in New Issue
Block a user