func (w *workload) Run(ctx context.Context) error {
	pool, err := db.NewPostgresDB(ctx, w.config.Conninfo)
	if err != nil {
		return err
	}
	defer pool.Close()
	naptime := w.config.Interval / time.Duration(w.config.Rate)
	timer := time.NewTimer(naptime)
	for {
		err = signalProcess(ctx, pool, w.config)
		if err != nil {
			w.logger.Warnf("failed terminate: %s", err)
		}
		select {
		case <-timer.C:
			timer.Reset(naptime)
			continue
		case <-ctx.Done():
			return nil
		}
	}
}
Run method connects to Postgres and starts the workload.
package terminate
import (
	"context"
	"fmt"
	"github.com/lesovsky/noisia"
	"github.com/lesovsky/noisia/db"
	"github.com/lesovsky/noisia/log"
	"time"
)
type Config struct {
	Conninfo string
	Interval time.Duration
	Rate uint16
	SoftMode bool
	IgnoreSystemBackends bool
	ClientAddr string
	User string
	Database string
	ApplicationName string
}
func (c Config) validate() error {
	if c.Interval < 10*time.Millisecond {
		return fmt.Errorf("terminate interval must be greater than 10ms")
	}
	if c.Rate < 1 {
		return fmt.Errorf("terminate rate must be greater than zero")
	}
	return nil
}
type workload struct {
	config Config
	logger log.Logger
}
func NewWorkload(config Config, logger log.Logger) (noisia.Workload, error) {
	err := config.validate()
	if err != nil {
		return nil, err
	}
	return &workload{config, logger}, nil
}