watcher

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HelperPath        string
	HelperDestination string
	HelperFile        string
	HelperExt         string
	HelperOperation   string
	HelperPattern     string
)

Functions

func Hash added in v0.2.1

func Hash(ev event.Event) string

Hash returns a md5 hash composed of an event File, Path, and Ext

func TestEventSetup added in v1.0.0

func TestEventSetup(t *testing.T) *event.Event

TestEventSetup sets up a new event for testing purposes

func TestProducerConsumer added in v1.0.0

func TestProducerConsumer() (Producer, Consumer)

TestProducerConsumer returns a Producer/Consumer struct for testing

func TestSimulateMultipleEvents added in v1.0.0

func TestSimulateMultipleEvents(operationList []string, t *testing.T) []event.Event

TestSimulateMultipleEvents takes a list of operations as args ["CREATE", "WRITE", "CLOSEWRITE"] and returns them as a list of events

Types

type Consumer

type Consumer interface {
	// Receive an event from the producer
	Receive(path, event string)
	// Process an event
	Process(e *event.Event)
	// Process a dir event
	ProcessDirEvent(e *event.Event)
}

Consumer interface Must implement Receive(), and Process() methods

type PathConsumer

type PathConsumer struct {
	// Path to watch
	Path string
	// Destination to move files to
	Destination string
	// File extenstion
	Ext string
	// Regex Pattern
	Pattern regexp.Regexp
}

PathConsumer is a consumer that consumes events from a path and moves them to a destination

func (*PathConsumer) Process

func (pc *PathConsumer) Process(e *event.Event)

Process takes an event and moves it to the destination

func (*PathConsumer) ProcessDirEvent

func (pc *PathConsumer) ProcessDirEvent(e *event.Event)

ProcessDirEvent takes an event and scans files ext

func (*PathConsumer) Receive

func (pc *PathConsumer) Receive(path, ev string)

Receive takes a path and an event operation, determines its validity and passes it to be processed it if valid

type PathWatcher

type PathWatcher struct {
	// List of consumers
	Consumers []*Consumer
	// Queue
	Queue *Q
	// Watcher instance
	Watcher fsnotify.Watcher
	// Path to watch
	Path string
}

PathWatcher is a producer that watches a path for events

func TestPathWatcher added in v1.0.0

func TestPathWatcher() *PathWatcher

TestPathWatcher returns a test watcher

func (*PathWatcher) AddPath

func (pw *PathWatcher) AddPath(path string)

AddPath adds a path to the watcher

func (*PathWatcher) Notify added in v0.2.1

func (pw *PathWatcher) Notify(path, event string)

Notify consumers of an event

func (*PathWatcher) Observe

func (pw *PathWatcher) Observe(pollInterval int)

Observe the producer

func (*PathWatcher) Poll added in v0.2.1

func (pw *PathWatcher) Poll(interval int)

Poll polls the queue for valid events given an interval (in seconds)

func (*PathWatcher) Register

func (pw *PathWatcher) Register(consumer *Consumer)

Register a consumer to the producer

func (*PathWatcher) Unregister

func (pw *PathWatcher) Unregister(consumer *Consumer)

Unregister a consumer from the producer

type Producer

type Producer interface {
	// Register a consumer to the producer
	Register(consumer *Consumer)
	// Unregister a consumer from the producer
	Unregister(consumer *Consumer)
	// Notify consumers of an event
	Notify(path, event string)
	// Observe the producer
	Observe(pollInterval int)
}

Producer interface for the watcher Must implement Register(), Unregister(), and Observe(), and notify()

type Q added in v0.2.1

type Q struct {
	Queue map[string]event.Event
}

Q holds the Queue

func NewQueue added in v0.2.1

func NewQueue() *Q

NewQueue create a new Q object

func (*Q) Add added in v0.2.1

func (q *Q) Add(ev event.Event)

Add adds to the queue

func (*Q) Empty added in v0.2.1

func (q *Q) Empty() bool

Empty returns a bool indicating if the queue is empty or not

func (*Q) Remove added in v0.2.1

func (q *Q) Remove(hash string)

Remove removes an item from the queue

func (*Q) Retrieve added in v0.2.1

func (q *Q) Retrieve(hash string) event.Event

Retrieve get an item from the queue given a valid hash

func (*Q) Size added in v0.2.1

func (q *Q) Size() int

Size returns the size of the queue

Jump to

Keyboard shortcuts

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