dalga

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const Version = "1.0.0"

Variables

View Source
var (
	ErrExist    = errors.New("job already exists")
	ErrNotExist = errors.New("job does not exist")
)
View Source
var DefaultConfig = Config{
	MySQL: mysqlConfig{
		Host:     "127.0.0.1",
		Port:     3306,
		DB:       "test",
		Table:    "dalga",
		User:     "root",
		Password: "",
	},
	Listen: listenConfig{
		Host: "127.0.0.1",
		Port: 34006,
	},
	Endpoint: endpointConfig{
		BaseURL: "http://127.0.0.1:5000/",
		Timeout: 10,
	},
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Jobs     jobsConfig
	MySQL    mysqlConfig
	Listen   listenConfig
	Endpoint endpointConfig
	Redis    redisConfig
}

func (*Config) LoadFromFile

func (c *Config) LoadFromFile(filename string) error

type Dalga

type Dalga struct {
	Jobs *JobManager
	// contains filtered or unexported fields
}

func New

func New(config Config) (*Dalga, error)

func (*Dalga) CreateTable

func (d *Dalga) CreateTable() error

CreateTable creates the table for storing jobs on database.

func (*Dalga) NotifyReady

func (d *Dalga) NotifyReady() <-chan struct{}

NotifyReady returns a channel that will be closed when Dalga is ready to accept HTTP requests.

func (*Dalga) Run

func (d *Dalga) Run() error

Run Dalga. This function is blocking. Returns nil after Shutdown is called.

func (*Dalga) Shutdown

func (d *Dalga) Shutdown()

Shutdown running Dalga gracefully.

type Job

type Job struct {
	JobKey
	// Interval is the duration between each POST to the endpoint.
	// Interval is 0 for one-off jobs.
	Interval time.Duration
	// NextRun is the next run time of the job, stored in UTC.
	NextRun time.Time
}

Job is the record stored in jobs table. Primary key for the table is JobKey.

func (*Job) MarshalJSON

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

func (*Job) OneOff

func (j *Job) OneOff() bool

OneOff returns true for one-off jobs. One-off jobs are stored with 0 interval on jobs table.

func (*Job) Remaining

func (j *Job) Remaining() time.Duration

Remaining returns the remaining time to the job's next run time.

func (*Job) String

func (j *Job) String() string

String returns the job in human-readable form.

type JobKey

type JobKey struct {
	// Path is where the job is going to be POSTed when it's time came.
	Path string
	// Body of POST request.
	Body string
}

type JobManager

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

func (*JobManager) Cancel

func (m *JobManager) Cancel(path, body string) error

Cancel deletes the job with path and body.

func (*JobManager) Get

func (m *JobManager) Get(path, body string) (*Job, error)

Get returns the job with path and body.

func (*JobManager) Running

func (m *JobManager) Running() int

Running returns the number of running jobs currently.

func (*JobManager) Schedule

func (m *JobManager) Schedule(path, body string, oneOff, immediate bool, firstRun *time.Time, interval *time.Duration) (*Job, error)

Schedule inserts a new job to the table or replaces existing one. Returns the created or replaced job.

func (*JobManager) Total

func (m *JobManager) Total() (int64, error)

Total returns the count of all jobs in jobs table.

func (*JobManager) Trigger

func (m *JobManager) Trigger(path, body string) (*Job, error)

Trigger runs the job immediately and resets it's next run time.

Directories

Path Synopsis
Godeps
_workspace/src/code.google.com/p/gcfg
Package gcfg reads "INI-style" text-based configuration files with "name=value" pairs grouped into sections (gcfg files).
Package gcfg reads "INI-style" text-based configuration files with "name=value" pairs grouped into sections (gcfg files).
_workspace/src/code.google.com/p/gcfg/scanner
Package scanner implements a scanner for gcfg configuration text.
Package scanner implements a scanner for gcfg configuration text.
_workspace/src/code.google.com/p/gcfg/token
Package token defines constants representing the lexical tokens of the gcfg configuration syntax and basic operations on tokens (printing, predicates).
Package token defines constants representing the lexical tokens of the gcfg configuration syntax and basic operations on tokens (printing, predicates).
_workspace/src/code.google.com/p/gcfg/types
Package types defines helpers for type conversions.
Package types defines helpers for type conversions.
_workspace/src/github.com/bmizerany/pat
Package pat implements a simple URL pattern muxer
Package pat implements a simple URL pattern muxer
_workspace/src/github.com/cenkalti/backoff
Package backoff implements backoff algorithms for retrying operations.
Package backoff implements backoff algorithms for retrying operations.
_workspace/src/github.com/fzzy/radix/redis/resp
This package provides an easy to use interface for creating and parsing messages encoded in the REdis Serialization Protocol (RESP).
This package provides an easy to use interface for creating and parsing messages encoded in the REdis Serialization Protocol (RESP).
_workspace/src/github.com/go-sql-driver/mysql
Go MySQL Driver - A MySQL-Driver for Go's database/sql package The driver should be used via the database/sql package: import "database/sql" import _ "github.com/go-sql-driver/mysql" db, err := sql.Open("mysql", "user:password@/dbname") See https://github.com/go-sql-driver/mysql#usage for details
Go MySQL Driver - A MySQL-Driver for Go's database/sql package The driver should be used via the database/sql package: import "database/sql" import _ "github.com/go-sql-driver/mysql" db, err := sql.Open("mysql", "user:password@/dbname") See https://github.com/go-sql-driver/mysql#usage for details

Jump to

Keyboard shortcuts

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