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
- type PublishFunc
- type REST
- type Service
- func (s *Service) CreateJob(ctx context.Context, req *schedulerpb.CreateJobRequest) (*schedulerpb.Job, error)
- func (s *Service) DeleteJob(ctx context.Context, req *schedulerpb.DeleteJobRequest) (*emptypb.Empty, error)
- func (s *Service) GetJob(ctx context.Context, req *schedulerpb.GetJobRequest) (*schedulerpb.Job, error)
- func (s *Service) ListJobs(ctx context.Context, req *schedulerpb.ListJobsRequest) (*schedulerpb.ListJobsResponse, error)
- func (s *Service) PauseJob(ctx context.Context, req *schedulerpb.PauseJobRequest) (*schedulerpb.Job, error)
- func (s *Service) ResumeJob(ctx context.Context, req *schedulerpb.ResumeJobRequest) (*schedulerpb.Job, error)
- func (s *Service) RunJob(ctx context.Context, req *schedulerpb.RunJobRequest) (*schedulerpb.Job, error)
- func (s *Service) Started() uint64
- func (s *Service) Sync()
- func (s *Service) UpdateJob(ctx context.Context, req *schedulerpb.UpdateJobRequest) (*schedulerpb.Job, error)
Constants ¶
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.
type Service ¶
type Service struct {
schedulerpb.UnimplementedCloudSchedulerServer
// contains filtered or unexported fields
}
Service holds jobs and fires them on schedule.
func New ¶
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 (s *Service) CreateJob(ctx context.Context, req *schedulerpb.CreateJobRequest) (*schedulerpb.Job, error)
func (*Service) DeleteJob ¶
func (s *Service) DeleteJob(ctx context.Context, req *schedulerpb.DeleteJobRequest) (*emptypb.Empty, error)
func (*Service) GetJob ¶
func (s *Service) GetJob(ctx context.Context, req *schedulerpb.GetJobRequest) (*schedulerpb.Job, error)
func (*Service) ListJobs ¶
func (s *Service) ListJobs(ctx context.Context, req *schedulerpb.ListJobsRequest) (*schedulerpb.ListJobsResponse, error)
func (*Service) PauseJob ¶
func (s *Service) PauseJob(ctx context.Context, req *schedulerpb.PauseJobRequest) (*schedulerpb.Job, error)
func (*Service) ResumeJob ¶
func (s *Service) ResumeJob(ctx context.Context, req *schedulerpb.ResumeJobRequest) (*schedulerpb.Job, error)
func (*Service) RunJob ¶
func (s *Service) RunJob(ctx context.Context, req *schedulerpb.RunJobRequest) (*schedulerpb.Job, error)
RunJob fires a job now, ahead of its schedule, without disturbing its next scheduled fire.
func (*Service) Started ¶
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 ¶
func (s *Service) UpdateJob(ctx context.Context, req *schedulerpb.UpdateJobRequest) (*schedulerpb.Job, error)
UpdateJob replaces the mutable fields and re-arms if the schedule changed.