WIP pubsub and sync logic

This commit is contained in:
mcrakhman 2022-07-14 14:28:37 +02:00 committed by Mikhail Iudin
parent bc1a0cf678
commit 1ee6a4c7cb
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
2 changed files with 57 additions and 0 deletions

13
service/sync/pubsub.go Normal file
View File

@ -0,0 +1,13 @@
package sync
type PubSubPayload struct {
}
type PubSub interface {
Send(msg *PubSubPayload) error
Listen(chan *PubSubPayload) error
}
func NewPubSub(topic string) PubSub {
return nil
}

44
service/sync/service.go Normal file
View File

@ -0,0 +1,44 @@
package sync
import (
"context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
)
type service struct {
pubSub PubSub
}
const CName = "SyncService"
func (s *service) Init(ctx context.Context, a *app.App) (err error) {
return nil
}
func (s *service) Name() (name string) {
return CName
}
func (s *service) Run(ctx context.Context) (err error) {
ch := make(chan *PubSubPayload)
err = s.pubSub.Listen(ch)
if err != nil {
return
}
return nil
}
func (s *service) Close(ctx context.Context) (err error) {
return nil
}
func (s *service) listen(ctx context.Context, ch chan *PubSubPayload) {
for {
select {
case <-ctx.Done():
return
case payload := <-ch:
// TODO: get object from object service and try to perform sync
}
}
}