api

package
v0.0.0-...-1fa5987 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

TODO: Large portions of this package should be hoisted out of internal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithVariables

func ContextWithVariables(ctx context.Context, vars ContextVariables) context.Context

func CreateJob

func CreateJob(ctx context.Context, svc Service, mutation string, arguments map[string]any) (jobID string, err error)

Schedule asynchronous execution of a GraphQL mutation.

func Mutate

func Mutate(ctx context.Context, svc Service, m any, vars map[string]any) error

func OperationData

func OperationData(resp any) any

Extracts the operation data from a response structures. The response data must contain exactly one top-level field.

func Query

func Query(ctx context.Context, svc Service, q any, vars map[string]any) error

func ToQueryError

func ToQueryError(err error) *errors.QueryError

Types

type ContextVariables

type ContextVariables struct {
	JobID    string `json:"jobId"`
	TaskID   string `json:"id"`
	WorkerID string `json:"workerId"`
}

func CurrentContextVariables

func CurrentContextVariables(ctx context.Context) *ContextVariables

type EventLogger

type EventLogger struct {
	Service    Service
	SystemLog  logging.Logger
	SourceType string
	SourceID   string
	Prefix     string
}

Logger that creates message events for a given source.

func NewSystemLogger

func NewSystemLogger(svc Service) *EventLogger

func (*EventLogger) Infof

func (el *EventLogger) Infof(format string, v ...any)

func (*EventLogger) Sublogger

func (sl *EventLogger) Sublogger(prefix string) logging.Logger

type Instant

type Instant = scalars.Instant

type JSONObject

type JSONObject = scalars.JSONObject

type QueryErrorSet

type QueryErrorSet []*errors.QueryError

func ToQueryErrorSet

func ToQueryErrorSet(err error) QueryErrorSet

func (QueryErrorSet) Error

func (errs QueryErrorSet) Error() string

func (QueryErrorSet) Unwrap

func (errs QueryErrorSet) Unwrap() error

type Service

type Service interface {
	// TODO: This should not be on the interface exposed to most callers.
	Shutdown(context.Context) error
	// Execute a GraphQL operation synchronously, decoding the response data in to res.
	// Implementations should also respect CurrentContextVariables.
	Do(ctx context.Context, res any, doc string, vars map[string]any) error
	// Begin a GraphQL subscription operation. Decodes responses in to the result
	// of invoking newRes for each event response. Decoded responses are
	// delivered to to consumers via Subscription.Events().
	Subscribe(ctx context.Context, newRes func() any, doc string, vars map[string]any) Subscription
}

type Subscription

type Subscription interface {
	// Yields events until the subscription is stopped.  The element type is
	// specified via the original Subscribe() method call.
	Events() <-chan any
	Err() error
	Stop()
}

func Subscribe

func Subscribe(ctx context.Context, svc Service, s any, vars map[string]any) Subscription

Like Query and Mutate, but the reflective structure will not be modified directly. Instead, a new instance will be allocated for each event.

type ULID

type ULID = scalars.ULID

type Worker

type Worker struct {
	Service Service
	ID      string
	// If non-empty, only work tasks from the specified job.  Otherwise, work any
	// available task.
	JobID string
	// Called when there is no more work expected.
	OnDone func()
}

func (*Worker) Run

func (worker *Worker) Run(acquireCtx context.Context, workCtx context.Context) error

We need a separate acquire context, so that we can cancel task acquisition immediately without cancelling tasks that are currently being worked. TODO: Figure out some less awkward interface for this.

type WorkerPool

type WorkerPool struct {
	Service      Service
	Concurrency  int
	WorkerPrefix string
	JobID        string
}

func (*WorkerPool) Run

func (pool *WorkerPool) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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