workers

package
v0.0.0-...-8ccb3ad Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WorkQueue = make(chan WorkRequest, 100)

A buffered channel that we can send work requests on.

View Source
var WorkerQueue chan chan WorkRequest

Functions

func AddJob

func AddJob(message WorkRequest)

func SetQueueType

func SetQueueType(queue string)

func SetupNSQ

func SetupNSQ(host, port string)

func StartBolt

func StartBolt(boltDir string, boltPerms os.FileMode) error

func StartDispatcher

func StartDispatcher(nworkers int, ApiKey string)

Types

type APIToken

type APIToken struct {
	Token string `json:"token"`
}

type Devices

type Devices struct {
	Tokens  []string `json:"tokens"`
	Sensors []string `json:"sensors"`
}

Devices ... object to hold tokens for Android/IOS/Web and Sensors

type Payload

type Payload struct {
	Device *string          `json:"device"`
	Name   *string          `json:"name"`
	Data   *json.RawMessage `json:"payload"`
}

type RefreshToken

type RefreshToken struct {
	NewToken string `json:"newtoken"`
	OldToken string `json:"oldtoken"`
	Topic
}

RefreshToken ... Describes a struct to update a device token with a refreshed token

func (*RefreshToken) Refresh

func (refreshToken *RefreshToken) Refresh() error

Refresh ... Logic to replace one token with another

type Registration

type Registration struct {
	Topic
	Token string `json:"token"`
}

Registration ... object to hold a registration request

func (*Registration) JoinTopic

func (register *Registration) JoinTopic() error

JoinTopic ... Join a new endpoint device to an already created topic

func (*Registration) LeaveTopic

func (register *Registration) LeaveTopic() error

LeaveTopic ... Remove a device token from a topic

func (*Registration) Register

func (register *Registration) Register() error

Register ... Register a new endpoint device

type Sensor

type Sensor struct {
	Topic
	Device string `json:"device"`
	Name   string `json:"name,omitempty"`
}

Sensor ... Describes a struct containing a sensor device and a topic with optional friendly name

func (*Sensor) Exists

func (sensor *Sensor) Exists() bool

Exists ... Check if a sensor by the id given has been registered with its topic

func (*Sensor) Register

func (sensor *Sensor) Register() error

Register ... Register a device and persist it in bolt

type Topic

type Topic struct {
	TopicString string `json:"topic,omitempty"`
}

type User

type User struct {
	UserID string `json:"user_id"`
	Email  string `json:"email"`
	Token  string `json:"token"`
}

func GetUser

func GetUser(user_id, email string) (User, error)

type WorkRequest

type WorkRequest struct {
	//Sensor `json:"sensor"`
	Token string           `json:"token"`
	Data  *json.RawMessage `json:"data"`
}

func (*WorkRequest) PublishToFirebase

func (work *WorkRequest) PublishToFirebase() error

func (*WorkRequest) PublishToNSQ

func (work *WorkRequest) PublishToNSQ() error

type Worker

type Worker struct {
	ID          int
	Work        chan WorkRequest
	WorkerQueue chan chan WorkRequest
	QuitChan    chan bool
}

func NewWorker

func NewWorker(id int, workerQueue chan chan WorkRequest) Worker

NewWorker creates, and returns a new Worker object. Its only argument is a channel that the worker can add itself to whenever it is done its work.

func (*Worker) Start

func (w *Worker) Start(ApiKey string)

This function "starts" the worker by starting a goroutine, that is an infinite "for-select" loop.

func (*Worker) Stop

func (w *Worker) Stop()

Stop tells the worker to stop listening for work requests.

Note that the worker will only stop *after* it has finished its work.

Jump to

Keyboard shortcuts

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