cron

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusNew     = 100 // Job has not run
	StatusRunning = 101

	// Codes for temorarily stopped jobs
	StatusStopped       = 200
	StatusStoppedSystem = 201
	StatusStoppedUser   = 202

	// Codes that indicates jobs that have run until completeion
	StatusDone         = 300
	StatusExpiredCount = 301
	StatusExpiredDate  = 302
	StatusDeleted      = 303

	StatusFailed = 500
)

Status codes for jobs

View Source
const ConfigDeletePushTokenOnSendError = true

ConfigDeletePushTokenOnSendError sets if tokens that have error on send are deleted from the database.

View Source
const CronContextName = "CRON"

CronContextName holds the cron service in gin context objects

View Source
const EnablePushMessaging = true

Variables

This section is empty.

Functions

func CronInserter

func CronInserter(cron *CronSender) gin.HandlerFunc

CronInserter is a gin middleware that will insert a CronSender driver into the context.

func DbDeleteCronbox

func DbDeleteCronbox(tx gorp.SqlExecutor, cb models.Cronbox) (bool, error)

func DbDeleteCronboxAndTemplate

func DbDeleteCronboxAndTemplate(tx gorp.SqlExecutor, cb models.Cronbox) (bool, error)

func DbDeleteMessage

func DbDeleteMessage(tx gorp.SqlExecutor, m models.Message) (bool, error)

func DbDeleteMessageId

func DbDeleteMessageId(tx gorp.SqlExecutor, messageID string) (bool, error)

func DbGetCronboxByJobID

func DbGetCronboxByJobID(tx gorp.SqlExecutor, id models.JobID) (*models.Cronbox, error)

func DbGetCronboxesForAll

func DbGetCronboxesForAll(tx gorp.SqlExecutor) ([]models.Cronbox, error)

func DbGetCronboxesForOwner

func DbGetCronboxesForOwner(tx gorp.SqlExecutor, owner models.OwnerID) ([]models.Cronbox, error)

func DbGetJobTemplate

func DbGetJobTemplate(tx gorp.SqlExecutor, jobId models.JobID) (*models.Message, error)

func DbGetMessageByID

func DbGetMessageByID(tx gorp.SqlExecutor, id string) (*models.Message, error)

func DbUpdateCronbox

func DbUpdateCronbox(tx gorp.SqlExecutor, cb models.Cronbox) (bool, error)

func IsExpired

func IsExpired(job *models.Cronbox) bool

IsExpired return true if a cronjob has expired.

func IsRunnable

func IsRunnable(job *models.Cronbox) bool

func SecureRandomAlphaString

func SecureRandomAlphaString(length int) string

TODO: Duplicated from helper.go

func SecureRandomBytes

func SecureRandomBytes(length int) []byte

SecureRandomBytes returns the requested number of bytes using crypto/rand

Types

type CronSender

type CronSender struct {
	DbMap     *gorp.DbMap
	FcmClient *messaging.Client
	// contains filtered or unexported fields
}

CronSender is a Gin middleware for sending and storing delayed and repeated messages

func (*CronSender) DeleteScheduledMessage

func (cs *CronSender) DeleteScheduledMessage(jobID models.JobID) (bool, error)

DeleteScheduledMessage stops a job (if running) and remove it from the db

func (*CronSender) GetCronboxes

func (cs *CronSender) GetCronboxes(owner models.OwnerID) ([]models.Cronbox, error)

GetCronboxes returns all cronbox jobs for owner.

func (*CronSender) InitializeFromDB

func (cs *CronSender) InitializeFromDB() error

InitializeFromDB loads jobs from database and into memory.

func (*CronSender) ScheduleMessage

func (cs *CronSender) ScheduleMessage(schedule string, timezone string, expire time.Time, repetitions int, owner string, message *models.Message) (*models.Cronbox, error)

ScheduleMessage will send the given message according to given schedule. The function will fail if the message is not present in the database. Return the jobid of the scheduled job.

func (*CronSender) StartCronbox

func (cs *CronSender) StartCronbox(JobID models.JobID) error

StartCronbox sets cronbox state to running

func (*CronSender) StopCronbox

func (cs *CronSender) StopCronbox(JobID models.JobID, status int) error

StopCronbox sets cronbox state to stopped and remove from cron if running

Jump to

Keyboard shortcuts

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