jobs_queue

package module
v0.0.0-...-3de45bb Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 5 Imported by: 0

README

Scheduled tasks/jobs queue runner

Helps to run scheduled tasks in background.

Example

JobsQueue.Functions["plus"] = func(params map[string]interface{}) (interface{}, error) {
	o1 := value.ToMapGet(params, "o1").Int()
	o2 := value.ToMapGet(params, "o2").Int()
	return o1 + o2, nil
}

JobsQueue.AddJob("plus", map[string]interface{}{"o1": 1, "o2": 2}, time.Now(), "")
JobsQueue.AddJob("plus", map[string]interface{}{"o1": 2, "o2": 3}, time.Now(), "")
JobsQueue.AddJob("plus", map[string]interface{}{"o1": 3, "o2": 4}, time.Now(), "15s")
JobsQueue.AddJob("plus", map[string]interface{}{"o1": 4, "o2": 5}, time.Now(), nil)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobsQueue

type JobsQueue struct {
	DB *dbm.DB

	CycleSleepTime int // seconds
	JobsPerCycle   int
	Functions      map[string]func(map[string]interface{}) (interface{}, error)
	// contains filtered or unexported fields
}

func New

func New(cycleSleepTime int, jobsPerCycle int, db *dbm.DB) *JobsQueue

func (*JobsQueue) AddJob

func (jq *JobsQueue) AddJob(function string, params map[string]interface{}, t time.Time, repeat interface{}) error

func (*JobsQueue) Restart

func (jq *JobsQueue) Restart()

func (*JobsQueue) Start

func (jq *JobsQueue) Start()

func (*JobsQueue) Stop

func (jq *JobsQueue) Stop()

Jump to

Keyboard shortcuts

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