gg_scheduler

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: BSD-3-Clause Imports: 7 Imported by: 8

README

Scheduler

Schedule everything.

Configuration

Scheduler is fully configurable.

{
    "uid": "Sample Scheduler",
    "sync": false,
    "schedules": [
      {
        "uid": "sample_1",
        "start_at": "",
        "timeline": "second:30"
      },
      {
        "uid": "sample_2",
        "start_at": "11:00:00",
        "timeline": "hour:12"
      }
    ]
}

Parameters

  • uid: A name for your scheduler (used in logs).
  • sync: Default is False. Enable sync mode if you need that OnSchedule events are locking.
  • schedules: Array of schedule objects. You can have more than one single scheduled job.
    • uid: A name used to identify a schedule in the array
    • start_at: (Optional) Time you want to launch e trigger.
    • timeline: Duration of your scheduled cycle. Do you want to launch a trigger every 5 minutes? Just set the timeline to "minute:5"

Sample Code

    sched := lygo_scheduler.NewSchedulerFromFile("./scheduler.json")
	if sched.HasErrors(){
		fmt.Println("Parsing Errors", sched.GetErrors())
	} else {
        sched.OnSchedule(func(schedule *lygo_scheduler.SchedulerTask) {
        	// do something useful here....
            fmt.Println("EVENT", schedule.Settings().Uid, schedule.Settings().StartAt, schedule.Settings().Timeline)
        })
        sched.Start()
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schedule

type Schedule struct {
	Uid       string                 `json:"uid,omitempty"`
	StartAt   string                 `json:"start_at"` // hh:mm ss (optional)
	Timeline  string                 `json:"timeline"` // minutes:1, hour:24, second:10
	Payload   map[string]interface{} `json:"payload,omitempty"`
	Arguments []interface{}          `json:"-"` // custom attachments
}

func (*Schedule) String

func (instance *Schedule) String() string

type Scheduler

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

func NewScheduler

func NewScheduler() *Scheduler

func NewSchedulerFromFile

func NewSchedulerFromFile(configFile string) *Scheduler

func NewSchedulerWithSettings

func NewSchedulerWithSettings(settings *SchedulerSettings) *Scheduler

func (*Scheduler) AddSchedule

func (instance *Scheduler) AddSchedule(item *Schedule, args ...interface{})

func (*Scheduler) AddScheduleByJson

func (instance *Scheduler) AddScheduleByJson(json string, args ...interface{})

func (*Scheduler) CountHandlers

func (instance *Scheduler) CountHandlers() int

func (*Scheduler) GetErrors

func (instance *Scheduler) GetErrors() string

func (*Scheduler) GetTimeout

func (instance *Scheduler) GetTimeout() time.Duration

func (*Scheduler) GoString

func (instance *Scheduler) GoString() string

func (*Scheduler) HasErrors

func (instance *Scheduler) HasErrors() bool

func (*Scheduler) IsAsync

func (instance *Scheduler) IsAsync() bool

func (*Scheduler) IsPaused

func (instance *Scheduler) IsPaused() bool

func (*Scheduler) IsStarted

func (instance *Scheduler) IsStarted() bool

func (*Scheduler) Join

func (instance *Scheduler) Join()

func (*Scheduler) OnError

func (instance *Scheduler) OnError(handler SchedulerErrorHandler)

func (*Scheduler) OnSchedule

func (instance *Scheduler) OnSchedule(handler SchedulerTaskHandler)

func (*Scheduler) Pause

func (instance *Scheduler) Pause()

func (*Scheduler) Reload

func (instance *Scheduler) Reload()

func (*Scheduler) Resume

func (instance *Scheduler) Resume()

func (*Scheduler) SetAsync

func (instance *Scheduler) SetAsync(value bool)

func (*Scheduler) Start

func (instance *Scheduler) Start()

func (*Scheduler) Stop

func (instance *Scheduler) Stop()

func (*Scheduler) String

func (instance *Scheduler) String() string

func (*Scheduler) TogglePause

func (instance *Scheduler) TogglePause()

func (*Scheduler) Uid

func (instance *Scheduler) Uid() string

type SchedulerErrorHandler

type SchedulerErrorHandler func(err string)

type SchedulerSettings

type SchedulerSettings struct {
	Uid       string      `json:"uid"`
	Sync      bool        `json:"sync"`
	Schedules []*Schedule `json:"schedules"`
}

func (*SchedulerSettings) String

func (instance *SchedulerSettings) String() string

type SchedulerTask

type SchedulerTask struct {
	Uid       string
	Arguments []interface{}
	Payload   map[string]interface{}
	// contains filtered or unexported fields
}

func NewSchedulerTask

func NewSchedulerTask(schedulerUid string, settings *Schedule) *SchedulerTask

func (*SchedulerTask) Error

func (instance *SchedulerTask) Error() string

func (*SchedulerTask) GoString

func (instance *SchedulerTask) GoString() string

func (*SchedulerTask) IsReady

func (instance *SchedulerTask) IsReady() bool

func (*SchedulerTask) Settings

func (instance *SchedulerTask) Settings() *Schedule

func (*SchedulerTask) String

func (instance *SchedulerTask) String() string

type SchedulerTaskHandler

type SchedulerTaskHandler func(schedule *SchedulerTask)

Jump to

Keyboard shortcuts

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