job

package
v0.0.0-...-932f842 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package job is used to run a daemon to run batch jobs on a schedule

Index

Constants

This section is empty.

Variables

View Source
var LogDivider = strings.Repeat("=", 80)

LogDivider can be used to divide logical sections in the log output.

Functions

func CreateSchema

func CreateSchema(ctx context.Context, conn *pgx.Conn) error

CreateSchema will create the job schema and associated tables needed for this package to run

Types

type Entry

type Entry struct {
	App     string
	Env     string
	URL     string
	RootDir string
	JobID   int
	RunID   int
	Name    string
	NameKey string
	Fun     string
	DB      *pgxpool.Pool
	Log     *logging.Logger
	Ctx     context.Context
}

Entry stores resources and information about running jobs. Can be used by running jobs to call utility methods.

func (*Entry) Exec

func (j *Entry) Exec(ctx context.Context, sql string, args ...any) error

Exec runs an SQL statement that does not need results back. The function Will print the query and then log rows affected and runtime when finished.

func (*Entry) GetEtag

func (e *Entry) GetEtag(nurl *url.URL) (string, error)

GetEtag retrieve the last known etag for the provided url.

func (*Entry) GetParm

func (e *Entry) GetParm(key string, seq int, val any) error

GetParm retrieves the current jobs parm with the given key and sequence

func (*Entry) LogMultiLineString

func (j *Entry) LogMultiLineString(s string)

LogMultiLineString prints out a multiline string and prints a line number for each line

func (*Entry) RunCmd

func (j *Entry) RunCmd(ctx context.Context, cmdstr string) error

RunCmd will execute the given command and log its output

func (*Entry) SetEtag

func (e *Entry) SetEtag(nurl *url.URL, etag string) error

SetEtag records the etag for the provided url.

func (*Entry) SetParm

func (e *Entry) SetParm(key string, seq int, p any) error

SetParm sets the current jobs parm with the given key and sequence

type Manager

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

Manager is an instance of a job manager.

func NewManager

func NewManager(options *ManagerOptions) (*Manager, error)

NewManager initializes a new job manager and returns a pointer.

func (*Manager) Run

func (m *Manager) Run()

Run starts the job submitting and monitoring process.

type ManagerOptions

type ManagerOptions struct {
	App            string
	Env            string
	URL            string
	DB             *pgxpool.Pool
	RootDir        string
	LogDir         string
	ScanInterval   time.Duration
	MaxConcurrency int
	RunCallback    RunCallback
}

ManagerOptions contain the settings to use when creating a new job manager instance.

type RunCallback

type RunCallback func(*Entry) error

RunCallback will be called to run the submitted process.

Jump to

Keyboard shortcuts

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