scheduler

package
v1.4.3-rc7 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

How to submit a Generator to the scheduler

What is a generator and how should it be implemented?

In order to create a new generator (which will generate new tasks one by one) and add it to the scheduler there are 3 methods which should be implemented:

  1. GenerateTask() (Task, error)
    This method should implement the logic for generating a new task. 
    Basically, when this method is called by the scheduler it should return the next task until there are no more tasks to be generated.
    Also, the Task returned by this method should implement DoWork() method which should contain the logic that should be executed when this task is run by the scheduler.
    
  2. IsDone() bool
    This method should return true after the generator finished all the work and has no more tasks to generate.
    
  3. Reset()
    When this method is called the generator should reset to its initial state.
    After the generator is reset, it will generate new tasks as if it hadn't been used before.
    This is useful for periodic generators, because the scheduler will call this method when the generator is done and has to wait a specific interval of time for this generator to become ready to run again.
    

Submit a generator

The scheduler accepts both periodic and non-periodic generators.

To submit a generator to the scheduler, SubmitGenerator should be called with the implemented generator, interval of time (which should be time.Duration(0) in case of non-periodic generator, or the interval for the periodic generator) and the priority of the tasks which will be generated by this generator as parameters.

Notes:

- A generator should submit only tasks having the same priority
- The priority of a task can be: LowPriorirty, MediumPriority or HighPriority

How to submit a Task to the scheduler

In order to create a new task and add it to the scheduler DoWork() error is the method that should be implemented. This should contain the logic that should be executed when this task is run by the scheduler.

To submit a task to the scheduler SubmitTask should be called with the implemented task and the priority of the task as parameters.

Note:

- A task can not be periodic. In order to add a periodic task, it can be created a generator which will generate periodically the same task.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator interface {
	GenerateTask() (Task, error)
	IsDone() bool
	Reset()
}

type Priority

type Priority int
const (
	LowPriority Priority = iota
	MediumPriority
	HighPriority
)

type Scheduler

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

func NewScheduler

func NewScheduler(logC log.Logger) *Scheduler

func (*Scheduler) RunScheduler

func (scheduler *Scheduler) RunScheduler(ctx context.Context)

func (*Scheduler) SubmitGenerator

func (scheduler *Scheduler) SubmitGenerator(taskGenerator Generator, interval time.Duration, priority Priority)

func (*Scheduler) SubmitTask

func (scheduler *Scheduler) SubmitTask(task Task, priority Priority)

type Task

type Task interface {
	DoWork() error
}

Jump to

Keyboard shortcuts

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