riverui

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: MPL-2.0 Imports: 34 Imported by: 11

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var FrontendIndex embed.FS

Functions

func NewEndpoints added in v0.12.0

func NewEndpoints[TTx any](client *river.Client[TTx], opts *EndpointsOpts[TTx]) uiendpoints.Bundle

NewEndpoints creates a new Endpoints bundle, which is a collection of API endpoints for a Handler. Endpoints must be provided to the Handler via the `Endpoints` option of `HandlerOpts`.

This constructor returns the open source riverui bundle, whereas `riverproui.NewEndpoints` returns the Pro-specific bundle with Pro APIs and features enabled.

func NewNotFoundJob added in v0.9.0

func NewNotFoundJob(jobID int64) *apierror.NotFound

func NewNotFoundQueue added in v0.9.0

func NewNotFoundQueue(name string) *apierror.NotFound

func NewNotFoundWorkflow added in v0.9.0

func NewNotFoundWorkflow(id string) *apierror.NotFound

func NormalizePathPrefix

func NormalizePathPrefix(prefix string) string

Types

type ConcurrencyConfig added in v0.9.0

type ConcurrencyConfig struct {
	GlobalLimit int32           `json:"global_limit"`
	LocalLimit  int32           `json:"local_limit"`
	Partition   PartitionConfig `json:"partition"`
}

type EndpointsOpts added in v0.12.0

type EndpointsOpts[TTx any] struct {
	// Tx is an optional transaction to wrap all database operations. It's mainly
	// used for testing.
	Tx *TTx
}

EndpointsOpts are the options for creating a new Endpoints bundle.

type Handler added in v0.12.0

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

Handler is an http.Handler that serves the River UI and API. It must be started with Start to initialize caching and background query functionality prior to serving requests. It can be directly mounted in an http.ServeMux and placed behind middleware, such as for authentication or logging.

Handlers are somewhat stateful with background services for caching, so they must be started with Start to initialize them prior to serving requests. They automatically stop as soon as the context is done.

func NewHandler added in v0.12.0

func NewHandler(opts *HandlerOpts) (*Handler, error)

NewHandler creates a new Handler that serves the River UI and API.

Example

ExampleNewHandler demonstrates how to create a River UI handler, embed it in an HTTP server, and make requests to its API endpoints.

package main

import (
	"context"
	"fmt"
	"io"
	"log/slog"
	"net/http"
	"net/http/httptest"
	"os"
	"strings"

	"github.com/jackc/pgx/v5/pgxpool"

	"github.com/riverqueue/river"
	"github.com/riverqueue/river/riverdriver/riverpgxv5"
	"github.com/riverqueue/river/rivershared/util/slogutil"

	"riverqueue.com/riverui"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Create a PostgreSQL connection pool. In a real application, you'd use your
	// own connection string or pool config.
	connConfig, err := pgxpool.ParseConfig(os.Getenv("TEST_DATABASE_URL"))
	if err != nil {
		panic(err)
	}

	dbPool, err := pgxpool.NewWithConfig(ctx, connConfig)
	if err != nil {
		panic(err)
	}
	defer dbPool.Close()

	// Create a River client with a message-only logger for reproducible output.
	// You can use any slog.Handler implementation in your application.
	logger := slog.New(&slogutil.SlogMessageOnlyHandler{Level: slog.LevelWarn})

	// Create a River client. We don't need to start the client since we're only
	// using it to demonstrate the UI.
	client, err := river.NewClient(riverpgxv5.New(dbPool), &river.Config{
		Logger: logger,
	})
	if err != nil {
		panic(err)
	}

	// Create the River UI handler. This handler implements http.Handler and can be
	// mounted in an HTTP mux
	handler, err := riverui.NewHandler(&riverui.HandlerOpts{
		DevMode:   true, // Use the live filesystem—don't use this outside tests
		Endpoints: riverui.NewEndpoints(client, nil),
		Logger:    logger,
		Prefix:    "/riverui", // Mount the UI under /riverui path
	})
	if err != nil {
		panic(err)
	}

	// Start the server to initialize background processes
	// This does not start an HTTP server
	if err := handler.Start(ctx); err != nil {
		panic(err)
	}

	// Create an HTTP mux and mount the River UI:
	mux := http.NewServeMux()
	mux.Handle("/riverui/", handler)

	// For this example, we use a test server to demonstrate API calls. In a
	// production environment, you would use http.ListenAndServe instead.
	testServer := httptest.NewServer(mux)
	defer testServer.Close()

	// Make a request to the jobs endpoint to demonstrate API usage:
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, testServer.URL+"/riverui/api/jobs?state=available", nil)
	if err != nil {
		panic(err)
	}
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	fmt.Printf("Status: %s\n", resp.Status)

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Response: %s\n", strings.TrimSpace(string(body)))

}
Output:

Status: 200 OK
Response: {"data":[]}

func (*Handler) ServeHTTP added in v0.12.0

func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP returns an http.ServeHTTP that can be mounted to serve HTTP requests.

func (*Handler) Start added in v0.12.0

func (h *Handler) Start(ctx context.Context) error

Start starts the handler's background services. Notably, this does _not_ cause the handler to start listening for HTTP in any way. To serve HTTP requests, the Handler implements `http.Handler` via a `ServeHTTP` method and can be mounted in an existing `http.ServeMux`.

type HandlerOpts added in v0.12.0

type HandlerOpts struct {
	// DevMode is whether the server is running in development mode.
	DevMode                  bool
	Endpoints                uiendpoints.Bundle
	JobListHideArgsByDefault bool
	// LiveFS is whether to use the live filesystem for the frontend.
	LiveFS bool
	// Logger is the logger to use logging errors within the handler.
	Logger *slog.Logger
	// Prefix is the path prefix to use for the API and UI HTTP requests.
	Prefix string
	// contains filtered or unexported fields
}

HandlerOpts are the options for creating a new Handler.

type PartitionConfig added in v0.9.0

type PartitionConfig struct {
	ByArgs []string `json:"by_args"`
	ByKind bool     `json:"by_kind"`
}

type RiverJob

type RiverJob struct {
	RiverJobMinimal

	Errors   []rivertype.AttemptError `json:"errors"`
	Metadata json.RawMessage          `json:"metadata"`
}

type RiverJobMinimal added in v0.10.0

type RiverJobMinimal struct {
	ID          int64           `json:"id"`
	Args        json.RawMessage `json:"args"`
	Attempt     int             `json:"attempt"`
	AttemptedAt *time.Time      `json:"attempted_at"`
	AttemptedBy []string        `json:"attempted_by"`
	CreatedAt   time.Time       `json:"created_at"`
	FinalizedAt *time.Time      `json:"finalized_at"`
	Kind        string          `json:"kind"`
	MaxAttempts int             `json:"max_attempts"`
	Priority    int             `json:"priority"`
	Queue       string          `json:"queue"`
	ScheduledAt time.Time       `json:"scheduled_at"`
	State       string          `json:"state"`
	Tags        []string        `json:"tags"`
}

type RiverQueue

type RiverQueue struct {
	CountAvailable int                `json:"count_available"`
	CountRunning   int                `json:"count_running"`
	CreatedAt      time.Time          `json:"created_at"`
	Concurrency    *ConcurrencyConfig `json:"concurrency"`
	Name           string             `json:"name"`
	PausedAt       *time.Time         `json:"paused_at"`
	UpdatedAt      time.Time          `json:"updated_at"`
}

Source Files

  • embed.go
  • handler.go
  • handler_api_endpoint.go
  • int64_string.go
  • spa_response_writer.go

Directories

Path Synopsis
cmd
riverui command
internal
riverproui module

Jump to

Keyboard shortcuts

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