watcher

package
v0.0.0-...-732aecd Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2014 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

The watcher package provides an interface for observing changes to arbitrary MongoDB documents that are maintained via the mgo/txn transaction package.

Index

Constants

This section is empty.

Variables

View Source
var Period time.Duration = 5 * time.Second

Period is the delay between each sync. It must not be changed when any watchers are active.

Functions

func MustErr

func MustErr(w Errer) error

MustErr returns the error with which w died. Calling it will panic if w is still running or was stopped cleanly.

func Stop

func Stop(w Stopper, t *tomb.Tomb)

Stop stops the watcher. If an error is returned by the watcher, t is killed with the error.

Types

type Change

type Change struct {
	// C and Id hold the collection name and document _id field value.
	C  string
	Id interface{}

	// Revno is the latest known value for the document's txn-revno
	// field, or -1 if the document was deleted.
	Revno int64
}

A Change holds information about a document change.

type Errer

type Errer interface {
	Err() error
}

Errer is implemented by all watchers.

type Stopper

type Stopper interface {
	Stop() error
}

Stopper is implemented by all watchers.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

A Watcher can watch any number of collections and documents for changes.

func New

func New(changelog *mgo.Collection) *Watcher

New returns a new Watcher observing the changelog collection, which must be a capped collection maintained by mgo/txn.

func (*Watcher) Dead

func (w *Watcher) Dead() <-chan struct{}

Dead returns a channel that is closed when the watcher has stopped.

func (*Watcher) Err

func (w *Watcher) Err() error

Err returns the error with which the watcher stopped. It returns nil if the watcher stopped cleanly, tomb.ErrStillAlive if the watcher is still running properly, or the respective error if the watcher is terminating or has terminated with an error.

func (*Watcher) StartSync

func (w *Watcher) StartSync()

StartSync forces the watcher to load new events from the database.

func (*Watcher) Stop

func (w *Watcher) Stop() error

Stop stops all the watcher activities.

func (*Watcher) Unwatch

func (w *Watcher) Unwatch(collection string, id interface{}, ch chan<- Change)

Unwatch stops watching the given collection and document id via ch.

func (*Watcher) UnwatchCollection

func (w *Watcher) UnwatchCollection(collection string, ch chan<- Change)

UnwatchCollection stops watching the given collection via ch.

func (*Watcher) Watch

func (w *Watcher) Watch(collection string, id interface{}, revno int64, ch chan<- Change)

Watch starts watching the given collection and document id. An event will be sent onto ch whenever a matching document's txn-revno field is observed to change after a transaction is applied. The revno parameter holds the currently known revision number for the document. Non-existent documents are represented by a -1 revno.

func (*Watcher) WatchCollection

func (w *Watcher) WatchCollection(collection string, ch chan<- Change)

WatchCollection starts watching the given collection. An event will be sent onto ch whenever the txn-revno field is observed to change after a transaction is applied for any document in the collection.

func (*Watcher) WatchCollectionWithFilter

func (w *Watcher) WatchCollectionWithFilter(collection string, ch chan<- Change, filter func(interface{}) bool)

WatchCollectionWithFilter starts watching the given collection. An event will be sent onto ch whenever the txn-revno field is observed to change after a transaction is applied for any document in the collection, so long as the specified filter function returns true when called with the document id value.

Jump to

Keyboard shortcuts

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