gcpscheduler

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 38 Imported by: 0

README

Cloud Scheduler

Parity grade: B · SDK cloud.google.com/go/scheduler@v1.17.0 · last audited 2026-10-18 (e410c4cd9)

Coverage

Metric Value
PARITY entries audited 10 (10 ok)
Feature families 9 (4 ok, 5 partial)
Known gaps 5
Deferred items 0
Resource leaks clean
Known gaps
  • Job state DISABLED and UPDATE_FAILED are never produced (updates are applied atomically); ResumeJob and PauseJob refuse them if they appear.
  • App Engine cron schedule syntax (every N minutes, every monday 09:00) is not supported; only unix-cron.
  • CreateJob does not validate the location against the supported-region catalog or the project against any registry.
  • Persisted in-flight attempts are not resumed mid-flight; after a restore the next cron slot or the persisted retry time applies.
  • Cloud Scheduler job-level max_doublings default (5) follows the documentation; the value the live service echoes was not verified.

More

Documentation

Index

Constants

View Source
const (
	// DefaultDispatchInterval is how often due jobs are picked up.
	DefaultDispatchInterval = 250 * time.Millisecond
)
View Source
const DefaultPort = 8124

DefaultPort is the dedicated gRPC listener's default TCP port.

Variables

View Source
var ErrNilAppContext = errors.New("gcpscheduler: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

Functions

func GetLocation

func GetLocation(req *location.GetLocationRequest) (*location.Location, error)

GetLocation returns one supported location.

func ListLocations

func ListLocations(req *location.ListLocationsRequest) ([]*location.Location, string, error)

ListLocations lists the supported locations of a project.

Types

type ConfigProvider

type ConfigProvider interface {
	GetGCPSchedulerSettings() Settings
}

ConfigProvider extracts Cloud Scheduler configuration from the AppContext Config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	// DispatchInterval is the dispatcher tick; zero disables the background dispatcher.
	DispatchInterval time.Duration
	Port             int
	// contains filtered or unexported fields
}

Handler serves the Cloud Scheduler gRPC API on a dedicated listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the supported gRPC methods.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler; the real API is gRPC on the dedicated port.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all in-memory state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Cloud Scheduler runs on its own gRPC listener.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the gRPC server and dispatcher, aborting in-flight attempts.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

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

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

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

InMemoryBackend holds all jobs under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend.

func (*InMemoryBackend) CreateJob

CreateJob creates a job under a location.

func (*InMemoryBackend) DeleteJob

func (b *InMemoryBackend) DeleteJob(name string) error

DeleteJob removes a job; in-flight attempts finish but their outcome is discarded.

func (*InMemoryBackend) DispatchDue

func (b *InMemoryBackend) DispatchDue()

DispatchDue starts every attempt that is due: cron fires first, then pending retries.

func (*InMemoryBackend) Drain

func (b *InMemoryBackend) Drain()

Drain blocks until every in-flight dispatch has finished.

func (*InMemoryBackend) GetJob

func (b *InMemoryBackend) GetJob(name string) (*schedulerpb.Job, error)

GetJob returns a job.

func (*InMemoryBackend) ListJobs

ListJobs lists the jobs of a location ordered by name.

func (*InMemoryBackend) PauseJob

func (b *InMemoryBackend) PauseJob(name string) (*schedulerpb.Job, error)

PauseJob stops an ENABLED job from firing.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all state.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads backend state from a snapshot; in-flight attempts at snapshot time are simply not resumed.

func (*InMemoryBackend) ResumeJob

func (b *InMemoryBackend) ResumeJob(name string) (*schedulerpb.Job, error)

ResumeJob re-enables a PAUSED job, scheduling its next fire time from now.

func (*InMemoryBackend) RunDispatcher

func (b *InMemoryBackend) RunDispatcher(ctx context.Context, every time.Duration)

RunDispatcher fires due jobs every interval until ctx ends.

func (*InMemoryBackend) RunJob

func (b *InMemoryBackend) RunJob(name string) (*schedulerpb.Job, error)

RunJob forces an immediate attempt regardless of state or schedule; it returns before the attempt completes.

func (*InMemoryBackend) SetAppEngineBaseURL

func (b *InMemoryBackend) SetAppEngineBaseURL(u string)

SetAppEngineBaseURL sets where AppEngineHttpTarget jobs are dispatched; empty disables them.

func (*InMemoryBackend) SetPublisher

func (b *InMemoryBackend) SetPublisher(p Publisher)

SetPublisher wires the Pub/Sub emulator that PubsubTarget jobs publish into; nil disables them.

func (*InMemoryBackend) SetRunContext

func (b *InMemoryBackend) SetRunContext(ctx context.Context)

SetRunContext sets the context in-flight dispatches run under; cancel it to abort them.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises jobs with their retry state.

func (*InMemoryBackend) UpdateJob

UpdateJob updates the masked fields of a job (all mutable fields when the mask is empty).

type Provider

type Provider struct{}

Provider implements service.Provider for Google Cloud Scheduler. It serves gRPC on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Publisher

type Publisher interface {
	Publish(req *pubsubpb.PublishRequest) ([]string, error)
}

Publisher is the slice of the Pub/Sub emulator that PubsubTarget jobs publish into.

type Settings

type Settings struct {
	AppEngineBaseURL string `` //nolint:lll // config struct tags are intentionally verbose
	/* 205-byte string literal not displayed */
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 207-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPScheduler.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

Jump to

Keyboard shortcuts

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