handlers

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaintenanceTaskQueue task queue name used for all the periodic maintenance jobs.
	// These are internal queue internal tasks
	MaintenanceTaskQueue string = "queue-maintenance"

	// RetentionTask is finished task cleanup type
	RetentionTask queue.TaskType = "retention"
)

Variables

View Source
var (
	// APIRequestTask marks a task as an API request task
	APIRequestTask queue.TaskType = "api-request"
)
View Source
var (
	// ErrNoHandlerFound occurs when dispatcher can'f find a registered handler for a task type
	ErrNoHandlerFound = errors.New("no handler found")
)
View Source
var (
	ErrSerializingHearbeat = errors.New("failed to serialize progress payload while sending heartbeat")
)

Functions

func AssertRetentionSchedule added in v1.12.0

func AssertRetentionSchedule(ctx context.Context, scheduler queue.Scheduler, queueName string, taskType queue.TaskType, status queue.TaskStatus, filter squirrel.Sqlizer, age time.Duration) error

AssertRetentionSchedule creates a new queue retention tasks for the supplied queue, finished tasks matching the supplied parameters will be deleted

func NewAPIRequestHandler added in v1.12.0

func NewAPIRequestHandler(tokenHeaderName string, tokenCreator tokens.Creator, client *http.Client) workers.TaskHandler

NewAPIRequestHandler creates a task handler that makes an HTTP request to a target API. The response from the request must be valid JSON or a stream of new line-separated JSON objects, otherwise the task will fail.

func NewDispatchHandler

func NewDispatchHandler(handlers map[queue.TaskType]workers.TaskHandler) workers.TaskHandler

NewDispatchHandler creates a task handler that will dispatch tasks to other handlers

func NewRetentionHandler added in v1.12.0

func NewRetentionHandler(db *sql.DB) workers.TaskHandler

NewRetentionHandler creates a task handler that will clean up old finished tasks

func NewSQLTaskHandler added in v1.12.0

func NewSQLTaskHandler(name string, db *sql.DB) workers.TaskHandler

NewSQLTaskHandler creates a sqlTaskHandler handler instance with the given tracing name

Types

type APIRequestProgress added in v1.12.0

type APIRequestProgress struct {
	// Stage is the current stage of the API request task
	Stage APIRequestStage `json:"stage,omitempty"`
	// Duration of the HTTP request
	Duration *time.Duration `json:"duration,omitempty"`
	// ReturnedStatus is a status returned from the target endpoint
	ReturnedStatus *int `json:"returnedStatus,omitempty"`
	// ReturnedBody is a body returned from the target endpoint
	ReturnedBody *string `json:"returnedBody,omitempty"`
	// ErrorMessage contains an error message string if it occurs during the update process
	ErrorMessage *string `json:"errorMessage,omitempty"`
}

APIRequestProgress describes the progress of the API request task stored during the heartbeat handling

type APIRequestStage added in v1.12.0

type APIRequestStage string
var (
	// RequestPreparing means the task is preparing the request parameters and the body
	RequestPreparing APIRequestStage = "preparing"
	// RequestPending means the request was sent, awaiting the response
	RequestPending APIRequestStage = "pending"
	// RequestResponse means the response was received
	RequestResponse APIRequestStage = "response"
)

type APIRequestTaskSpec added in v1.12.0

type APIRequestTaskSpec struct {
	// Method to use for the API request
	Method string `json:"method"`
	// URL is the target URL for the request.
	// Must be an absolute URL that contains the scheme and the host components.
	URL string `json:"url"`
	// RequestBody to send
	RequestBody string `json:"requestBody"`
	// RequestHeaders to send
	RequestHeaders map[string]string `json:"requestHeaders"`
	// Authorized if `true` the task will send a header with the
	// signed JWT token as a part of the request
	Authorized bool `json:"authorized"`
	// ExpectedStatus is an HTTP status expected as a response.
	// If it does not match the actual status the task fails
	ExpectedStatus int `json:"expectedStatus"`
}

APIRequestTaskSpec describes the specification of the API request task

type SQLExecTaskSpec added in v1.12.0

type SQLExecTaskSpec struct {
	// SQL is the actual sql that will be run
	SQL string `json:"sql"`
}

SQLExecTaskSpec defines a task that simply executes a single SQL statement. This can be used for simple CRON cleanup tasks, for example.

type SQLTaskProgress added in v1.12.0

type SQLTaskProgress struct {
	// Duration of the HTTP request in milliseconds
	Duration *int64 `json:"duration,omitempty"`
	// RowsAffected
	RowsAffected *int64 `json:"rowsAffected,omitempty"`
	// ErrorMessage contains an error message string if it occurs during the update process
	ErrorMessage *string `json:"errorMessage,omitempty"`
}

SQLTaskProgress contains the generic progress information for a sql task

Jump to

Keyboard shortcuts

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