realtime

package
v0.0.0-...-a7c217f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

View Source
const (
	EventCreate = "CREATED"
	EventUpdate = "UPDATED"
	EventDelete = "DELETED"
	EventNotify = "NOTIFIED"
)

Basic data events

Variables

This section is empty.

Functions

func LogHook

func LogHook(db prefixer.Prefixer, hub Hub, parentDocType, documentID string) logrus.Hook

LogHook creates a hook that transmits logs through redis pubsub messaging.

Types

type Doc

type Doc interface {
	ID() string
	DocType() string
}

Doc is an interface for a object with DocType, ID

type Event

type Event struct {
	Cluster int    `json:"cluster,omitempty"`
	Domain  string `json:"domain"`
	Prefix  string `json:"prefix,omitempty"`
	Verb    string `json:"verb"`
	Doc     Doc    `json:"doc"`
	OldDoc  Doc    `json:"old,omitempty"`
}

Event is the basic message structure manipulated by the realtime package

func (*Event) DBCluster

func (e *Event) DBCluster() int

DBCluster implements the prefixer.Prefixer interface.

func (*Event) DBPrefix

func (e *Event) DBPrefix() string

DBPrefix implements the prefixer.Prefixer interface.

func (*Event) DomainName

func (e *Event) DomainName() string

DomainName implements the prefixer.Prefixer interface.

type EventsChan

type EventsChan chan *Event

EventsChan is a chan of events

type Hub

type Hub interface {
	// Emit is used by publishers when an event occurs
	Publish(db prefixer.Prefixer, verb string, doc Doc, oldDoc Doc)

	// Subscriber creates a Subscriber that can subscribe to several
	// doctypes. Call its Close method to Unsubscribe.
	Subscriber(prefixer.Prefixer) *Subscriber

	// SubscribeFirehose adds a listener for all events that happened in this
	// cozy-stack process.
	SubscribeFirehose() *Subscriber
	// contains filtered or unexported methods
}

Hub is an object which recive events and calls appropriate listener

func GetHub

func GetHub() Hub

GetHub returns the global hub

type JSONDoc

type JSONDoc struct {
	M    map[string]interface{}
	Type string
}

JSONDoc is a map representing a simple json object that implements the couchdb.Doc interface.

Note: we can't use the couchdb.JSONDoc as the couchdb package imports the realtime package, and it would create an import loop. And we cannot move the JSONDoc from couchdb here, as some of its methods use other functions from the couchdb package.

func (JSONDoc) DocType

func (j JSONDoc) DocType() string

DocType returns the DocType of the document

func (JSONDoc) ID

func (j JSONDoc) ID() string

ID returns the ID of the document

func (*JSONDoc) MarshalJSON

func (j *JSONDoc) MarshalJSON() ([]byte, error)

MarshalJSON is used for marshalling the document to JSON, with the doctype as _type.

type Subscriber

type Subscriber struct {
	prefixer.Prefixer
	Channel EventsChan
	// contains filtered or unexported fields
}

Subscriber is used to subscribe to several doctypes

func (*Subscriber) Close

func (sub *Subscriber) Close()

Close will unsubscribe to all topics and the subscriber should no longer be used after that.

func (*Subscriber) Subscribe

func (sub *Subscriber) Subscribe(doctype string)

Subscribe adds a listener for events on a whole doctype

func (*Subscriber) Unsubscribe

func (sub *Subscriber) Unsubscribe(doctype string)

Unsubscribe removes a listener for events on a whole doctype

func (*Subscriber) Unwatch

func (sub *Subscriber) Unwatch(doctype, id string)

Unwatch removes a listener for events for a specific document (doctype+id)

func (*Subscriber) Watch

func (sub *Subscriber) Watch(doctype, id string)

Watch adds a listener for events for a specific document (doctype+id)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL