cloudscheduler

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package cloudscheduler is the Cloud Scheduler emulation.

A job is a cron expression and a target: run this URL, or publish to this topic, on this schedule. Unlike a Cloud Task, a job recurs — after each fire it re-arms for its next cron time. The whole cycle runs on the injected clock, so a daily job fires twenty-four times when a test advances a day, rather than once a day in real time. That is the thing a wall-clock emulator cannot do.

Index

Constants

View Source
const MaxBodyBytes = 4 << 20

MaxBodyBytes caps a JSON request body; the port is shared, so an unbounded read is a way to exhaust the process.

Variables

This section is empty.

Functions

This section is empty.

Types

type PublishFunc

type PublishFunc func(ctx context.Context, topic string, data []byte, attrs map[string]string) error

PublishFunc delivers a message to a Pub/Sub topic.

type REST

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

REST serves the Cloud Scheduler JSON API so `gcloud scheduler` works. The Go client speaks gRPC; gcloud speaks REST, over the same service.

func NewREST

func NewREST(s *Service) *REST

NewREST wires the routes gcloud drives.

func (*REST) Matches

func (a *REST) Matches(method, escapedPath string) bool

Matches reports whether a route here claims the request; /v1/ is shared.

func (*REST) ServeHTTP

func (a *REST) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Service

type Service struct {
	schedulerpb.UnimplementedCloudSchedulerServer
	// contains filtered or unexported fields
}

Service holds jobs and fires them on schedule.

func New

func New(kv store.Store, clk clock.Clock, publish PublishFunc) *Service

New wires a service and re-arms any jobs the store already holds. publish may be nil, in which case Pub/Sub-target jobs are dropped.

func (*Service) CreateJob

func (*Service) DeleteJob

func (s *Service) DeleteJob(ctx context.Context, req *schedulerpb.DeleteJobRequest) (*emptypb.Empty, error)

func (*Service) GetJob

func (*Service) ListJobs

func (*Service) PauseJob

func (*Service) ResumeJob

func (*Service) RunJob

RunJob fires a job now, ahead of its schedule, without disturbing its next scheduled fire.

func (*Service) Started

func (s *Service) Started() uint64

Started counts HTTP deliveries ever launched, so a drain can tell whether a pass triggered new work and needs another round.

func (*Service) Sync

func (s *Service) Sync()

Sync waits for in-flight HTTP fires. A test advancing the clock across a job's time uses this before asserting, since an HTTP target dispatches on a goroutine.

func (*Service) UpdateJob

UpdateJob replaces the mutable fields and re-arms if the schedule changed.

Jump to

Keyboard shortcuts

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