schedulers

package
v0.0.0-...-f9d50c0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 12 Imported by: 0

README

Adding a custom scheduler

IScheduler interface

The first thing a custom scheduler needs to implement is the ISchedulerinterface

	// IScheduler interface of scheduler
	IScheduler interface {
		Validate() ([]string, error)
		Execute(
			context.Context,
			*logger.Log,
			time.Duration,
			[]scenario.Action,
			string, // outputsDir
			users.UserGenerator,
			*connection.ConnectionSettings,
			*statistics.ExecutionCounters,
		) error
		RequireScenario() bool
		// PopulateHookData populate map with data which can be used by go template in hooks
		PopulateHookData(data map[string]interface{})
	}

Register a custom scheduler

Once there's an implementation of the Ischeduler interface it can be registered using the scheduler.RegisterScheduler or RegisterSchedulerOverride methods.

Examples registering a scheduler

The scheduler also needs to be registered using the RegisterScheduler method.

func init() {
	_ = scheduler.RegisterScheduler(MySchedulerName, MyScheduler{})
}

Overriding an existing scheduler with the same name can be done with the RegisterSchedulerOverride method.

func init() {
	_ = scheduler.RegisterSchedulerOverride(MySchedulerName, MyScheduler{})
}
Generated documentation

To have documentation for your scheduler included in the generated documentation, do

  1. Add a folder in data/schedulers/name_of_your_scheduler.
  2. Add two files in this folder description.md and examples.md with description and example of the scheduler.
  3. Add a doc-keytag for each setting of your scheduler and add an entry with same key in data/params.json.
  4. Generate files by running go generate.

Example scheduler

This package includes an example scheduler randomizing the period inbetween each user get introduced. An example script using this can be found in the examples folder.

Documentation

Index

Constants

View Source
const MySchedulerName = "myscheduler"

Variables

This section is empty.

Functions

This section is empty.

Types

type MyScheduler

type MyScheduler struct {
	scheduler.Scheduler
	Settings MySchedulerSettings `json:"settings" doc-key:"config.myscheduler.settings"`
}

func (MyScheduler) Execute

func (sched MyScheduler) Execute(
	ctx context.Context,
	log *logger.Log,
	timeout time.Duration,
	scenario []scenario.Action,
	outputsDir string,
	users users.UserGenerator,
	connectionSettings *connection.ConnectionSettings,
	counters *statistics.ExecutionCounters,
) error

Execute scheduler

func (MyScheduler) PopulateHookData

func (sched MyScheduler) PopulateHookData(data map[string]interface{})

PopulateHookData populate map with data which can be used by go template in hooks

func (MyScheduler) RequireScenario

func (sched MyScheduler) RequireScenario() bool

RequireScenario reports if the scheduler requires a scenario or not for scheduler validation.

func (MyScheduler) Validate

func (sched MyScheduler) Validate() ([]string, error)

Validate scheduler

type MySchedulerSettings

type MySchedulerSettings struct {
	ConcurrentUsers int `json:"concurrentUsers" displayname:"Concurrent users" doc-key:"config.scheduler.settings.concurrentusers"`
}

Jump to

Keyboard shortcuts

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