jobkit

package module
v0.0.0-...-a635af1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 42 Imported by: 0

README

jobkit

This package is meant to be a suite of helpers to make writing robust job workers easier.

It provides facilities that plug into go-sdk/cron to help with:

  • A management server to streamline allowing forced runs of jobs.
  • Sending email notifications for job results.
  • Sending slack notifications for job results.
  • Sending webhook notifications for job results.

Documentation

Index

Constants

View Source
const (
	DefaultMaxLogBytes   = 10 * (1 << 10)
	DefaultHistoryPath   = "_history"
	DefaultSkipExpandEnv = false
	DefaultDiscardOutput = false
	DefaultHideOutput    = false

	DefaultHistoryMaxCount = 256
	DefaultHistoryMaxAge   = 0

	DefaultHistoryDisabled            = false
	DefaultHistoryPersistenceDisabled = false

	DefaultSchedule = "* */1 * * * * *"
)

Constants and Defaults

View Source
const (
	// DefaultEmailMimeType is the default email mime type.
	DefaultEmailMimeType = "text/plain"

	// DefaultEmailSubjectTemplate is the default subject template.
	DefaultEmailSubjectTemplate = `{{.Var "jobName" }} :: {{ .Var "flag" }}{{ if .HasVar "elapsed" }} ({{ .Var "elapsed" }} elapsed){{end}}`

	// DefaultEmailHTMLBodyTemplate is the default email html body template.
	DefaultEmailHTMLBodyTemplate = `` /* 853-byte string literal not displayed */

	// DefaultEmailTextBodyTemplate is the default body template.
	DefaultEmailTextBodyTemplate = `` /* 231-byte string literal not displayed */

)
View Source
const (
	ShellActionLogFlag = "shell.action"
)

Logger Constants

Variables

This section is empty.

Functions

func DefaultParameterValues

func DefaultParameterValues(params ...Parameter) cron.JobParameters

DefaultParameterValues pulls the default parameter values off a set of jobkit parameters.

func ExpandParameters

func ExpandParameters(ji *cron.JobInvocation) func(string) string

ExpandParameters returns a new parameter expander for a given job invocation.

func NewEmailMessage

func NewEmailMessage(flag string, emailDefaults email.Message, ji *JobInvocation, options ...email.MessageOption) (email.Message, error)

NewEmailMessage returns a new email message.

func NewServer

func NewServer(jm *cron.JobManager, cfg Config, options ...web.Option) *web.App

NewServer returns a new management server that lets you trigger jobs or look at job statuses via. a json api.

func NewSlackMessage

func NewSlackMessage(flag string, defaults slack.Message, ji *JobInvocation, options ...slack.MessageOption) slack.Message

NewSlackMessage returns a new job started message.

func ParameterValuesAsEnviron

func ParameterValuesAsEnviron(params cron.JobParameters) (environ []string)

ParameterValuesAsEnviron returns params as environment values, i.e. key=value.

func ParameterValuesFromForm

func ParameterValuesFromForm(parameters []Parameter, formValues url.Values) cron.JobParameters

ParameterValuesFromForm creates a parameter values set from url values.

func ParameterValuesFromJSON

func ParameterValuesFromJSON(parameters []Parameter, data []byte) (cron.JobParameters, error)

ParameterValuesFromJSON creates a parameter values set from json data.

func WithJobInvocationOutput

func WithJobInvocationOutput(ctx context.Context, jio *JobInvocationOutput) context.Context

WithJobInvocationOutput adds a job invocation to a context.

Types

type Config

type Config struct {
	// Title is a descriptive title for the jobkit instance.
	// It defaults to `Jobkit`
	Title string `yaml:"title"`
	// UseViewFiles indicates if we should use local view files from the disk.
	UseViewFiles *bool `yaml:"useViewFiles"`
	// Cron is the cron manager config.
	Cron JobConfig `yaml:"cron"`
	// Email sets email defaults.
	EmailDefaults email.Message `yaml:"emailDefaults"`
	// Logger is the logger config.
	Logger logger.Config `yaml:"logger"`
	// Web is the web config used for the management server.
	Web web.Config `yaml:"web"`
	// SMTP is the smtp options.
	SMTP email.SMTPSender `yaml:"smtp"`
	// Datadog configures the datadog client.
	Datadog datadog.Config `yaml:"datadog"`
	// Slack configures the slack webhook sender.
	Slack slack.Config `yaml:"slack"`
	// Sentry confgures the sentry error collector.
	Sentry sentry.Config `yaml:"sentry"`
	// DB controls database connections for the job manager.
	DB db.Config `yaml:"db"`
}

Config is the jobkit config.

func (*Config) Resolve

func (c *Config) Resolve(ctx context.Context) error

Resolve applies resolution steps to the config.

func (Config) TitleOrDefault

func (c Config) TitleOrDefault() string

TitleOrDefault returns a property or a default.

func (Config) UseViewFilesOrDefault

func (c Config) UseViewFilesOrDefault() bool

UseViewFilesOrDefault returns a value or a default.

type HistoryMemory

type HistoryMemory struct {
	sync.RWMutex
	History map[string][]*JobInvocation
	Lookup  map[string]*JobInvocation
}

HistoryMemory is a memory backed history store.

func (*HistoryMemory) Add

Add adds a result.

func (*HistoryMemory) AddMany

func (hm *HistoryMemory) AddMany(_ context.Context, invocations ...*JobInvocation) error

AddMany adds multiple invocations to the history store.

func (*HistoryMemory) Cull

func (hm *HistoryMemory) Cull(_ context.Context, jobName string, maxCount int, maxAge time.Duration) error

Cull culls history.

func (*HistoryMemory) Get

func (hm *HistoryMemory) Get(_ context.Context, jobName string) ([]*JobInvocation, error)

Get returns all history for a given job.

func (*HistoryMemory) GetByID

func (hm *HistoryMemory) GetByID(_ context.Context, jobName, invocationID string) (*JobInvocation, error)

GetByID gets a job invocation by ID.

func (*HistoryMemory) Initialize

func (hm *HistoryMemory) Initialize(ctx context.Context) error

Initialize initializes the backing maps.

type HistoryPostgres

type HistoryPostgres struct {
	Conn *db.Connection
	Tx   *sql.Tx
}

HistoryPostgres implements a sqlite history provider.

func (*HistoryPostgres) Add

Add adds a result.

func (*HistoryPostgres) Cull

func (h *HistoryPostgres) Cull(ctx context.Context, jobName string, maxCount int, maxAge time.Duration) (err error)

Cull culls history.

func (*HistoryPostgres) Get

func (h *HistoryPostgres) Get(ctx context.Context, jobName string) (output []*JobInvocation, err error)

Get gets all results for a given job.

func (*HistoryPostgres) GetByID

func (h *HistoryPostgres) GetByID(ctx context.Context, jobName, invocationID string) (*JobInvocation, error)

GetByID gets a specific result.

func (*HistoryPostgres) Initialize

func (h *HistoryPostgres) Initialize(ctx context.Context) error

Initialize creates the schema for the provider.

type HistoryProvider

type HistoryProvider interface {
	Initialize(ctx context.Context) error
	Add(context.Context, *JobInvocation) error
	Get(context.Context, string) ([]*JobInvocation, error)
	GetByID(context.Context, string, string) (*JobInvocation, error)
	Cull(context.Context, string, int, time.Duration) error
}

HistoryProvider is a provider for jobkit history specifically.

type Job

type Job struct {
	Job         cron.Job
	JobConfig   JobConfig
	JobSchedule cron.Schedule

	Log         logger.Log
	StatsClient stats.Collector

	SlackDefaults   slack.Message
	EmailDefaults   email.Message
	WebhookDefaults Webhook

	SlackClient  slack.Sender
	SentryClient sentry.Sender
	EmailClient  email.Sender

	NotificationsQueueEmail   *RetryQueue
	NotificationsQueueSlack   *RetryQueue
	NotificationsQueueWebhook *RetryQueue

	HistoryProvider HistoryProvider
}

Job is the main job body.

func MustNewJob

func MustNewJob(wrapped cron.Job, options ...JobOption) *Job

MustNewJob returns a new job with a given set of options and panics if ther is an error.

func NewJob

func NewJob(wrapped cron.Job, options ...JobOption) (*Job, error)

NewJob returns a new job.

func (*Job) AddHistoryResult

func (job *Job) AddHistoryResult(ctx context.Context, ji *JobInvocation) error

AddHistoryResult adds an item to history and culls old items.

func (*Job) Config

func (job *Job) Config() cron.JobConfig

Config implements job config provider. One specific consideration is it merges the inner job's config parameters with the config parameters found on the wrapping jobkit job config.

func (*Job) CullHistory

func (job *Job) CullHistory(ctx context.Context) error

CullHistory triggers the history provider cull.

func (*Job) Debugf

func (job *Job) Debugf(ctx context.Context, format string, args ...interface{})

Debugf logs a debug message if the logger is set.

func (*Job) Error

func (job *Job) Error(ctx context.Context, err error) error

Error logs an error if the logger i set.

func (*Job) Execute

func (job *Job) Execute(ctx context.Context) (err error)

Execute is the job body.

func (*Job) Lifecycle

func (job *Job) Lifecycle() (output cron.JobLifecycle)

Lifecycle implements cron.LifecycleProvider.

func (*Job) Name

func (job *Job) Name() string

Name returns the job name.

func (*Job) OnBegin

func (job *Job) OnBegin(ctx context.Context)

OnBegin is a lifecycle event handler.

func (*Job) OnBroken

func (job *Job) OnBroken(ctx context.Context)

OnBroken is a lifecycle event handler.

func (*Job) OnCancellation

func (job *Job) OnCancellation(ctx context.Context)

OnCancellation is a lifecycle event handler.

func (*Job) OnComplete

func (job *Job) OnComplete(ctx context.Context)

OnComplete is a lifecycle event handler.

func (*Job) OnDisabled

func (job *Job) OnDisabled(ctx context.Context)

OnDisabled is a lifecycle event handler.

func (*Job) OnEnabled

func (job *Job) OnEnabled(ctx context.Context)

OnEnabled is a lifecycle event handler.

func (*Job) OnError

func (job *Job) OnError(ctx context.Context)

OnError is a lifecycle event handler.

func (*Job) OnFixed

func (job *Job) OnFixed(ctx context.Context)

OnFixed is a lifecycle event handler.

func (*Job) OnLoad

func (job *Job) OnLoad(ctx context.Context) error

OnLoad implements job on load handler.

func (*Job) OnSuccess

func (job *Job) OnSuccess(ctx context.Context)

OnSuccess is a lifecycle event handler.

func (*Job) OnUnload

func (job *Job) OnUnload(ctx context.Context) error

OnUnload implements job on unload handler.

func (*Job) Schedule

func (job *Job) Schedule() cron.Schedule

Schedule returns the job schedule.

type JobConfig

type JobConfig struct {
	cron.JobConfig    `yaml:",inline"`
	ShellActionConfig `yaml:",inline"`
	Name              string                 `yaml:"name"`
	Schedule          string                 `yaml:"schedule"`
	HistoryPath       string                 `yaml:"historyPath"`
	HistoryDisabled   *bool                  `yaml:"historyDisabled"`
	HistoryMaxAge     *time.Duration         `yaml:"historyMaxAge"`
	HistoryMaxCount   *int                   `yaml:"historyMaxCount"`
	Parameters        []Parameter            `yaml:"parameters"`
	Notifications     JobNotificationsConfig `yaml:"notifications"`
}

JobConfig is something you can use to give your jobs some knobs to turn from configuration. You can use this job config by embedding it into your larger job config struct.

func (JobConfig) HistoryDisabledOrDefault

func (jc JobConfig) HistoryDisabledOrDefault() bool

HistoryDisabledOrDefault returns a value or a default.

func (JobConfig) HistoryMaxAgeOrDefault

func (jc JobConfig) HistoryMaxAgeOrDefault() time.Duration

HistoryMaxAgeOrDefault returns a value or a default.

func (JobConfig) HistoryMaxCountOrDefault

func (jc JobConfig) HistoryMaxCountOrDefault() int

HistoryMaxCountOrDefault returns a value or a default.

func (JobConfig) HistoryPathOrDefault

func (jc JobConfig) HistoryPathOrDefault() string

HistoryPathOrDefault returns a value or a default.

func (JobConfig) ScheduleOrDefault

func (jc JobConfig) ScheduleOrDefault() string

ScheduleOrDefault returns a value or a default.

type JobInvocation

type JobInvocation struct {
	cron.JobInvocation
	JobInvocationOutput
}

JobInvocation is a serialized form of a job invocation.

func NewJobInvocation

func NewJobInvocation(ji *cron.JobInvocation) *JobInvocation

NewJobInvocation creates a new jobkit job invocation from a cron job invocation.

func (JobInvocation) MarshalJSON

func (ji JobInvocation) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*JobInvocation) UnmarshalJSON

func (ji *JobInvocation) UnmarshalJSON(contents []byte) error

UnmarshalJSON unmarhsals

type JobInvocationOutput

type JobInvocationOutput struct {
	Output         *bufferutil.Buffer
	OutputHandlers *bufferutil.BufferHandlers
}

JobInvocationOutput is a wrapping job invocation.

func GetJobInvocationOutput

func GetJobInvocationOutput(ctx context.Context) *JobInvocationOutput

GetJobInvocationOutput gets a job invocation from a context.

func NewJobInvocationOutput

func NewJobInvocationOutput() *JobInvocationOutput

NewJobInvocationOutput returns a new job invocation output.

type JobNotificationsConfig

type JobNotificationsConfig struct {
	Slack slack.Message `yaml:"slack"`
	// Email holds the message defaults for email notifications.
	Email email.Message `yaml:"email"`
	// Webhook set a webhook target for notifications.
	Webhook Webhook `yaml:"webhook"`

	// MaxRetries is the maximum number of retries before we give up on a notification.
	MaxRetries *int `yaml:"maxRetries"`
	// RetryWait is the time between attempts.
	RetryWait *time.Duration `yaml:"retryWait"`

	// OnBegin governs if we should send notifications job start.
	OnBegin *bool `yaml:"onBegin"`
	// OnComplete governs if we should send notifications on any success.
	OnComplete *bool `yaml:"onComplete"`
	// OnSuccess governs if we should send notifications on any success.
	OnSuccess *bool `yaml:"onSuccess"`
	// OnFailure governs if we should send notifications on any failure.
	OnError *bool `yaml:"onError"`
	// OnCancellation governs if we should send notifications on cancellation.
	OnCancellation *bool `yaml:"onCancellation"`
	// OnBroken governs if we should send notifications on a success => failure transition.
	OnBroken *bool `yaml:"onBroken"`
	// OnFixed governs if we should send notifications on a failure => success transition.
	OnFixed *bool `yaml:"onFixed"`
	// OnEnabled governs if we should send notifications when a job is enabled.
	OnEnabled *bool `yaml:"onEnabled"`
	// OnDisabled governs if we should send notifications when a job is disabled.
	OnDisabled *bool `yaml:"onDisabled"`
}

JobNotificationsConfig are the notification options for a job.

func (JobNotificationsConfig) MaxRetriesOrDefault

func (jnc JobNotificationsConfig) MaxRetriesOrDefault() int

MaxRetriesOrDefault returns a value or a default.

func (JobNotificationsConfig) OnBeginOrDefault

func (jnc JobNotificationsConfig) OnBeginOrDefault() bool

OnBeginOrDefault returns a value or a default.

func (JobNotificationsConfig) OnBrokenOrDefault

func (jnc JobNotificationsConfig) OnBrokenOrDefault() bool

OnBrokenOrDefault returns a value or a default.

func (JobNotificationsConfig) OnCancellationOrDefault

func (jnc JobNotificationsConfig) OnCancellationOrDefault() bool

OnCancellationOrDefault returns a value or a default.

func (JobNotificationsConfig) OnCompleteOrDefault

func (jnc JobNotificationsConfig) OnCompleteOrDefault() bool

OnCompleteOrDefault returns a value or a default.

func (JobNotificationsConfig) OnDisabledOrDefault

func (jnc JobNotificationsConfig) OnDisabledOrDefault() bool

OnDisabledOrDefault returns a value or a default.

func (JobNotificationsConfig) OnEnabledOrDefault

func (jnc JobNotificationsConfig) OnEnabledOrDefault() bool

OnEnabledOrDefault returns a value or a default.

func (JobNotificationsConfig) OnErrorOrDefault

func (jnc JobNotificationsConfig) OnErrorOrDefault() bool

OnErrorOrDefault returns a value or a default.

func (JobNotificationsConfig) OnFixedOrDefault

func (jnc JobNotificationsConfig) OnFixedOrDefault() bool

OnFixedOrDefault returns a value or a default.

func (JobNotificationsConfig) OnSuccessOrDefault

func (jnc JobNotificationsConfig) OnSuccessOrDefault() bool

OnSuccessOrDefault returns a value or a default.

func (JobNotificationsConfig) RetryWaitOrDefault

func (jnc JobNotificationsConfig) RetryWaitOrDefault() time.Duration

RetryWaitOrDefault returns a value or a default.

type JobOption

type JobOption func(*Job) error

JobOption is a function that mutates a job.

func OptJobConfig

func OptJobConfig(cfg JobConfig) JobOption

OptJobConfig sets the job config.

func OptJobHistory

func OptJobHistory(provider HistoryProvider) JobOption

OptJobHistory sets the job history provider.

func OptJobLog

func OptJobLog(log logger.Log) JobOption

OptJobLog sets the job logger.

func OptJobParsedSchedule

func OptJobParsedSchedule(schedule string) JobOption

OptJobParsedSchedule sets the schedule to a parsed cron string.

type JobStats

type JobStats struct {
	SuccessRate    float64       `json:"successRate"`
	OutputBytes    int           `json:"outputBytes"`
	RunsTotal      int           `json:"runsTotal"`
	RunsSuccessful int           `json:"runsSuccessful"`
	RunsErrored    int           `json:"runsErrored"`
	RunsCancelled  int           `json:"runsCancelled"`
	ElapsedMax     time.Duration `json:"elapsedMax"`
	ElapsedMin     time.Duration `json:"elapsedMin"`
	Elapsed50th    time.Duration `json:"elapsed50th"`
	Elapsed95th    time.Duration `json:"elapsed95th"`
}

JobStats represent stats about a job scheduler.

func HistoryStats

func HistoryStats(history []*JobInvocation) JobStats

HistoryStats returns job history stats.

type JobViewModel

type JobViewModel struct {
	Name          string
	Labels        map[string]string
	Disabled      bool
	Config        JobConfig
	Stats         JobStats
	Schedule      cron.Schedule
	NextRuntime   time.Time
	Current       *JobInvocation
	Last          *JobInvocation
	History       []*JobInvocation
	HistoryLookup map[string]*JobInvocation
}

JobViewModel is a viewmodel that represents a job.

func FilterJobViewModels

func FilterJobViewModels(jobs []*JobViewModel, predicate func(*JobViewModel) bool) (output []*JobViewModel)

FilterJobViewModels filters a set of job view models by a predicate.

func NewJobViewModel

func NewJobViewModel(js *cron.JobScheduler) (*JobViewModel, error)

NewJobViewModel returns a job view model from a job scheduler.

func NewJobViewModels

func NewJobViewModels(jobs map[string]*cron.JobScheduler) ([]*JobViewModel, error)

NewJobViewModels returns the job view models.

type ManagementServer

type ManagementServer struct {
	Config Config
	Cron   *cron.JobManager
}

ManagementServer is the jobkit management server.

func (ManagementServer) Register

func (ms ManagementServer) Register(app *web.App)

Register registers the management server.

func (ManagementServer) ViewPaths

func (ms ManagementServer) ViewPaths() []string

ViewPaths returns the view paths for the management server.

type Parameter

type Parameter struct {
	Label       string            `yaml:"label"`       // label will be a descriptive label next to the input
	Name        string            `yaml:"name"`        // name is the post form key on submission
	Required    bool              `yaml:"required"`    // indicates the value for this parameter must be set
	Placeholder string            `yaml:"placeholder"` // placeholder is used to show ghost text in an input.
	Value       string            `yaml:"value"`       // value is the default value or the provided value.
	Options     []ParameterOption `yaml:"options"`     // options are select input options; if they are set the param will be a select
}

Parameter is an option for a job invocation.

func (Parameter) RenderInput

func (p Parameter) RenderInput(attributes ...string) template.HTML

RenderInput returns the html string for the input.

func (Parameter) RenderLabel

func (p Parameter) RenderLabel(attributes ...string) template.HTML

RenderLabel returns the html string for the input label.

type ParameterOption

type ParameterOption struct {
	Value string
	Text  string
}

ParameterOption is an option for a parameter.

type RetryQueue

type RetryQueue struct {
	Parallelism       int
	MaxAttempts       int
	RetryWaitProvider func(*RetryQueueWorkItem) time.Duration
	Latch             *async.Latch
	Log               logger.Log
	Work              chan *RetryQueueWorkItem
	Action            async.WorkAction
	WaitHandles       map[string]*async.Latch
	WaitHandlesMux    sync.Mutex
}

RetryQueue is a queue that retries on error.

func NewRetryQueue

func NewRetryQueue(action async.WorkAction, options ...RetryQueueOption) *RetryQueue

NewRetryQueue returns a new retry queue.

func (*RetryQueue) Add

func (rq *RetryQueue) Add(ctx context.Context, item interface{})

Add adds an item to the queue.

func (*RetryQueue) NotifyStarted

func (rq *RetryQueue) NotifyStarted() <-chan struct{}

NotifyStarted returns the started notification channel.

func (*RetryQueue) NotifyStopped

func (rq *RetryQueue) NotifyStopped() <-chan struct{}

NotifyStopped returns the stopped notification channel.

func (*RetryQueue) Start

func (rq *RetryQueue) Start() error

Start starts the retry queue.

func (*RetryQueue) Stop

func (rq *RetryQueue) Stop() error

Stop stops the retry queue.

type RetryQueueOption

type RetryQueueOption func(*RetryQueue)

RetryQueueOption is an option or mutator for a retry queue.

func OptRetryQueueMaxAttempts

func OptRetryQueueMaxAttempts(maxAttempts int) RetryQueueOption

OptRetryQueueMaxAttempts sets the retry queue max attempts.

func OptRetryQueueRetryWait

func OptRetryQueueRetryWait(wait time.Duration) RetryQueueOption

OptRetryQueueRetryWait sets the retry wait to a const value.

func OptRetryQueueRetryWaitBackoff

func OptRetryQueueRetryWaitBackoff(base time.Duration) RetryQueueOption

OptRetryQueueRetryWaitBackoff sets the retry wait to be a backoff based on a base and the number of attempts.

func OptRetryQueueRetryWaitProvider

func OptRetryQueueRetryWaitProvider(waitProvider func(*RetryQueueWorkItem) time.Duration) RetryQueueOption

OptRetryQueueRetryWaitProvider sets the retry wait provider.

type RetryQueueWorkItem

type RetryQueueWorkItem struct {
	Context  context.Context
	Item     interface{}
	Attempts int
}

RetryQueueWorkItem is a work item for the retry queue.

type RetryQueueWorker

type RetryQueueWorker struct {
	Latch  *async.Latch
	Action async.WorkAction
	Work   chan *RetryQueueWorkItem

	OnStartHandler    func(*RetryQueueWorkItem)
	OnCompleteHandler func(*RetryQueueWorkItem)
	OnErrorHandler    func(*RetryQueueWorkItem, error)
}

RetryQueueWorker is a background worker for a retry queue.

func (*RetryQueueWorker) Execute

func (rqw *RetryQueueWorker) Execute(workItem *RetryQueueWorkItem)

Execute handles a work item.

func (*RetryQueueWorker) NotifyStarted

func (rqw *RetryQueueWorker) NotifyStarted() <-chan struct{}

NotifyStarted returns the started notification channel.

func (*RetryQueueWorker) NotifyStopped

func (rqw *RetryQueueWorker) NotifyStopped() <-chan struct{}

NotifyStopped returns the stopped notification channel.

func (*RetryQueueWorker) OnComplete

func (rqw *RetryQueueWorker) OnComplete(wi *RetryQueueWorkItem)

OnComplete handles on complete steps.

func (*RetryQueueWorker) OnError

func (rqw *RetryQueueWorker) OnError(wi *RetryQueueWorkItem, err error)

OnError handles on error steps.

func (*RetryQueueWorker) OnStart

func (rqw *RetryQueueWorker) OnStart(wi *RetryQueueWorkItem)

OnStart handles on start steps.

func (*RetryQueueWorker) Start

func (rqw *RetryQueueWorker) Start() error

Start starts the retry queue worker.

func (*RetryQueueWorker) Stop

func (rqw *RetryQueueWorker) Stop() error

Stop stops the retry queue worker.

type ShellAction

type ShellAction struct {
	Log    logger.Log
	Config ShellActionConfig
}

ShellAction captures options for a shell action.

func NewShellAction

func NewShellAction(exec []string, opts ...ShellActionOption) ShellAction

NewShellAction returns a new shell action.

func (ShellAction) Execute

func (se ShellAction) Execute(ctx context.Context) error

Execute is the job body.

type ShellActionConfig

type ShellActionConfig struct {
	// Exec is a job body that shells out for its action.
	Exec []string `yaml:"exec"`
	// SkipExpandEnv skips expanding environment variables in the exec segments.
	SkipExpandEnv *bool `yaml:"skipExpandEnv"`
	// DiscardOutput skips setting up output buffers for job invocations.
	DiscardOutput *bool `yaml:"discardOutput"`
	// HideOutput skips writing job output to standard output and standard error.
	HideOutput *bool `yaml:"hideOutput"`
}

ShellActionConfig is a config for shell actions.

func (ShellActionConfig) DiscardOutputOrDefault

func (se ShellActionConfig) DiscardOutputOrDefault() bool

DiscardOutputOrDefault returns a value or a default.

func (ShellActionConfig) HideOutputOrDefault

func (se ShellActionConfig) HideOutputOrDefault() bool

HideOutputOrDefault returns a value or a default.

func (ShellActionConfig) SkipExpandEnvOrDefault

func (se ShellActionConfig) SkipExpandEnvOrDefault() bool

SkipExpandEnvOrDefault returns a value or a default.

type ShellActionOption

type ShellActionOption func(*ShellAction)

ShellActionOption is a mutator for a shell action.

func OptShellActionConfig

func OptShellActionConfig(cfg ShellActionConfig) ShellActionOption

OptShellActionConfig sets the shell action config.

func OptShellActionLog

func OptShellActionLog(log logger.Log) ShellActionOption

OptShellActionLog sets the shell action logger.

type Webhook

type Webhook struct {
	Method  string            `yaml:"method"`
	URL     string            `yaml:"url"`
	Headers map[string]string `yaml:"headers"`
	Body    string            `yaml:"body"`
}

Webhook is a notification type.

func (Webhook) IsZero

func (wh Webhook) IsZero() bool

IsZero returns if the webhook is set or not.

func (Webhook) MethodOrDefault

func (wh Webhook) MethodOrDefault() string

MethodOrDefault returns the webhoook method.

func (Webhook) Options

func (wh Webhook) Options(options ...r2.Option) []r2.Option

Options realizes the webhook as a set of r2 options.

func (Webhook) Request

func (wh Webhook) Request(options ...r2.Option) *r2.Request

Request creates a new r2 request for the webhook.

Directories

Path Synopsis
cmd
job

Jump to

Keyboard shortcuts

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