metre

package module
v0.0.0-...-3606fc6 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2017 License: MIT Imports: 11 Imported by: 0

README

metre

Golang cron framework. Scheduling through ØMQ push-pull and state managed through redis

Requirements

Installation

go get github.com/gospackler/metre

Documentation

Example

Check TestMasterSlave() function in metre_test.go

Authors

Documentation

Overview

TODO : Split broker and Master into two.

Package metre is used to schedule end execute cron jobs in a simplified fashion

Index

Constants

View Source
const (
	Status msgType = iota
	Request
	Debug
	Error
)
View Source
const DealerPort string = "5556" // Default port for queue
View Source
const LocalHost string = "tcp://127.0.0.1" // Default host for cache and queue
View Source
const RouterPort string = "5555" // Default port for queue

Variables

This section is empty.

Functions

func CleanResponseMessage

func CleanResponseMessage(msg string) (string, error)

func CreateErrorMsg

func CreateErrorMsg(err error, id, uid, jobguid string) string

func SerializeMsg

func SerializeMsg(msgObj *MetreMessage) string

func StartBroker

func StartBroker(dealerUri string, routerUri string)

Types

type Master

type Master struct {
	Cron       cron.Cron
	SchInpChan chan *SchInput
	TaskMap    map[string]*Task
	// contains filtered or unexported fields
}

Master is the representation of a master server. It can register tasks which gets scheduled periodically. Multiple master instances can connect to a broker. The schParallel defines the number of request connections to the broker.

func NewMaster

func NewMaster(routerUri string, schParallel int) (*Master, error)

Remove dealer from the picture in Master.

func (*Master) AddTask

func (m *Master) AddTask(t *Task)

func (*Master) Schedule

func (m *Master) Schedule(taskId string, uid string) (string, error)

FIXME : Scheduling happens here. Is this the right design ?

func (*Master) ScheduleFromId

func (m *Master) ScheduleFromId(ID string) error

func (*Master) Start

func (m *Master) Start()

type Metre

type Metre struct {
	MessageChannel chan string
	MasterIns      *Master
	SlaveIns       *Slave
}

func New

func New(m *Master, s *Slave) (*Metre, error)

New creates a new scheduler to manage task scheduling and states

func (*Metre) Add

func (m *Metre) Add(t *Task)

Add adds a cron job task to schedule and process

type MetreMessage

type MetreMessage struct {
	// JobGUID is the low-level unique id that metre will track between master and slaves.
	JobGUID string `json:"job_guid"`
	// UID is the application level unique id that the app can track for it's own purpose.
	UID         string  `json:"uid"`
	MessageType msgType `json:"msg_type"`
	TaskId      string  `json:"task_id"`
	Message     string  `json:"message"`
}

The set of messages metre passes between master and slave.

func CreateMsg

func CreateMsg(mt msgType, id, uid, jobguid, msg string) *MetreMessage

func ParseMessage

func ParseMessage(msg string) (*MetreMessage, error)

type SchInput

type SchInput struct {
	Input     string
	RespChan  chan string
	ErrorChan chan error
}

func NewScheduleInput

func NewScheduleInput(inp string) *SchInput

func (*SchInput) Close

func (s *SchInput) Close()

type Slave

type Slave struct {
	TaskMap map[string]*Task
	// contains filtered or unexported fields
}

Slave has a set of workers which listens for request's Each of these workers, work in parallel, thanks to ZMQ

func NewSlave

func NewSlave(dealerUri string, processParallel int) (*Slave, error)

FIXME : Use procesParallel in some way.

func (*Slave) AddTask

func (s *Slave) AddTask(t *Task)

func (*Slave) GetResponse

func (s *Slave) GetResponse(m string) (ret string)

func (*Slave) Listen

func (s *Slave) Listen(id int)

func (*Slave) StartSlave

func (s *Slave) StartSlave()

type Task

type Task struct {
	sync.Mutex
	MessageChannel chan string
	StartTime      time.Time
	ID             string // Type Type of task (user as class prefix in cache)
	Interval       string // Schedule String in cron notation
	Schedule       func(*Master) error
	Process        func(*MetreMessage) (string, error)
}

func (*Task) Evaluate

func (t *Task) Evaluate(msg *MetreMessage)

func (Task) GetID

func (t Task) GetID() string

func (*Task) SendMessage

func (t *Task) SendMessage(msg string)

func (*Task) Zero

func (t *Task) Zero()

Zeros the parameters that may change in a run()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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