sched

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 License: BSD-3-Clause Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const ISOUTCTimeLayout = "2006-01-02T15:04:05Z"

ISOUTCTimeLayout format string for ISO standard time

Variables

View Source
var ErrAccessDenied = errors.New("access denied")

ErrAccessDenied not enough permissions

View Source
var ErrExpiredToken = errors.New("token is expired")

ErrExpiredToken not enough permissions

View Source
var ErrInconsistentState = errors.New("task already accepted")

ErrInconsistentState when you try to accept an already accepted task

View Source
var ErrTaskNotFound = errors.New("task not found")

ErrTaskNotFound could not find the referenced task

Functions

func IntInSlice

func IntInSlice(num int, slice []int) bool

IntInSlice checks if a int is inside of a certain slice of ints

func Notify

func Notify(jt *JobTarget, jDB *JobDB) error

Notify send a notification for the given JobTarget

func NotifyGorush

func NotifyGorush(bu string, jt *JobTarget) error

NotifyGorush tell gorush to notify clients

func SetTaskState

func SetTaskState(tID string, uID string,
	state string, validStates []string,
	updateTimeCol string,
	db *sqlx.DB) error

SetTaskState sets the state of the task

func SetTokenExpired added in v0.2.5

func SetTokenExpired(db *sqlx.DB, uID string) error

SetTokenExpired marks the token of the uID as expired

Types

type AlertData

type AlertData struct {
	ID      string                 `json:"id"`
	Message string                 `json:"message" binding:"required"`
	Extra   map[string]interface{} `json:"extra"`
}

AlertData is the alert message

type GinSchedMiddleware

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

GinSchedMiddleware a database aware middleware. It will set the DB property, that can be accessed via: db := c.MustGet("DB").(*sqlx.DB)

func InitSchedMiddleware

func InitSchedMiddleware(db *sqlx.DB) (*GinSchedMiddleware, error)

InitSchedMiddleware create the middleware that injects the database

func (*GinSchedMiddleware) MiddlewareFunc

func (mw *GinSchedMiddleware) MiddlewareFunc() gin.HandlerFunc

MiddlewareFunc this is what you register as the middleware

type GoRushLog added in v0.2.5

type GoRushLog struct {
	Type     string `json:"type"`
	Platform string `json:"platform"`
	Token    string `json:"token"`
	Message  string `json:"message"`
	Error    string `json:"error"`
}

GoRushLog contains details about the failure. It is available when core->sync in the gorush settings (https://github.com/appleboy/gorush#features) is true. For expired tokens Error will be: * "Unregistered" or "BadDeviceToken" on iOS https://stackoverflow.com/questions/42511476/what-are-the-possible-reasons-to-get-apns-responses-baddevicetoken-or-unregister https://github.com/sideshow/apns2/blob/master/response.go#L85 * "NotRegistered" or "InvalidRegistration" on Android: See: https://github.com/appleboy/go-fcm/blob/master/response.go

type GoRushNotification

type GoRushNotification struct {
	Tokens           []string               `json:"tokens"`
	Platform         int                    `json:"platform"`
	Message          string                 `json:"message"`
	Topic            string                 `json:"topic"`
	To               string                 `json:"to"`
	Data             map[string]interface{} `json:"data"`
	ContentAvailable bool                   `json:"content_available"`
	Notification     map[string]string      `json:"notification"`
}

GoRushNotification contains all the notification metadata for gorush

type GoRushReq

type GoRushReq struct {
	Notifications []*GoRushNotification `json:"notifications"`
}

GoRushReq is a wrapper for a gorush notification request

type GoRushResponse added in v0.2.5

type GoRushResponse struct {
	Counts  int         `json:"counts"`
	Success string      `json:"success"`
	Logs    []GoRushLog `json:"logs"`
}

GoRushResponse is a response from gorush on /api/push

type Job

type Job struct {
	ID       string
	Schedule Schedule
	Delay    int64
	Comment  string

	NextRunAt time.Time
	TimesRun  int64

	IsDone bool
	// contains filtered or unexported fields
}

Job container

func NewJob

func NewJob(jID string, comment string, schedule Schedule, delay int64) *Job

NewJob create a new job

func (*Job) CreateTask

func (j *Job) CreateTask(cID string, t *TaskData, jDB *JobDB) (string, error)

CreateTask creates a new task and stores it in the JobDB

func (*Job) GetTargets

func (j *Job) GetTargets(jDB *JobDB) []*JobTarget

GetTargets returns all the targets for the job

func (*Job) GetWaitDuration

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

GetWaitDuration gets the amount of time to wait for the task to run next

func (*Job) Run

func (j *Job) Run(jDB *JobDB)

Run the given job

func (*Job) Save

func (j *Job) Save(jDB *JobDB) error

Save the job to the job database

func (*Job) ShouldRun

func (j *Job) ShouldRun() bool

ShouldRun checks if we should run this job

func (*Job) ShouldWait

func (j *Job) ShouldWait() bool

ShouldWait returns true if the job is not done

func (*Job) WaitAndRun

func (j *Job) WaitAndRun(jDB *JobDB)

WaitAndRun will wait on the job and then run it when it's time

type JobDB

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

JobDB keep track of the Job database

func (*JobDB) GetAll

func (db *JobDB) GetAll() ([]*Job, error)

GetAll returns a list of all jobs in the database

type JobTarget

type JobTarget struct {
	ClientID  string
	TaskID    *string
	TaskData  *TaskData
	AlertData *AlertData
	Token     string
	Platform  string
}

JobTarget the target of a job

func NewJobTarget

func NewJobTarget(cID string, token string, plat string, tid *string, td *TaskData, ad *AlertData) *JobTarget

NewJobTarget create a new job target instance

type NotifyReq

type NotifyReq struct {
	ClientIDs []string               `json:"client_ids"`
	Event     map[string]interface{} `json:"event"`
}

NotifyReq is the reuqest for sending this particular notification message XXX this is duplicated in proteus-notify

type Schedule

type Schedule struct {
	Repeat    int64
	StartTime time.Time
	Duration  ScheduleDuration
}

Schedule metadata about a schedule

func ParseSchedule

func ParseSchedule(s string) (Schedule, error)

ParseSchedule parse a schedule string

type ScheduleDuration

type ScheduleDuration struct {
	Years   float64
	Months  float64
	Weeks   float64
	Days    float64
	Hours   float64
	Minutes float64
	Seconds float64
}

ScheduleDuration datastructure for scheduling information

func ParseDuration

func ParseDuration(s string) (ScheduleDuration, error)

ParseDuration parses a duration string

func (*ScheduleDuration) ToDuration

func (d *ScheduleDuration) ToDuration() time.Duration

ToDuration convert to a time.Duration

type Scheduler

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

Scheduler is the datastructure for the scheduler

func NewScheduler

func NewScheduler(db *sqlx.DB) *Scheduler

NewScheduler creates a new instance of the scheduler

func (*Scheduler) DeleteJob

func (s *Scheduler) DeleteJob(jobID string) error

DeleteJob will remove the job by removing it from the running jobs

func (*Scheduler) RunJob

func (s *Scheduler) RunJob(j *Job)

RunJob checks if we should wait on the job and if not will run it

func (*Scheduler) Shutdown

func (s *Scheduler) Shutdown()

Shutdown do all the shutdown logic

func (*Scheduler) Start

func (s *Scheduler) Start()

Start the scheduler

type TaskData

type TaskData struct {
	ID        string                 `json:"id"`
	TestName  string                 `json:"test_name" binding:"required"`
	Arguments map[string]interface{} `json:"arguments"`
	State     string
}

TaskData is the data for the task

func GetTask

func GetTask(tID string, uID string, db *sqlx.DB) (TaskData, error)

GetTask returns the specified task with the ID

Jump to

Keyboard shortcuts

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