Documentation ¶
Overview ¶
Package snapshoter This package provides the ability to snapshot all the schedules in the scheduler job store and persist them in the DB in GOB binary format. Also it provides ability to bootstrap the scheduler from this snapshot so that the scheduler can run catchup for all the schedules from the snapshotted time.
Index ¶
- type Metrics
- type Persistence
- type Reader
- type Snapshot
- type SnapshotV1
- func (s *SnapshotV1) Create() Snapshot
- func (s *SnapshotV1) Deserialize(snapshot []byte) error
- func (s *SnapshotV1) GetLastExecutionTime(key string) *time.Time
- func (s *SnapshotV1) GetVersion() int
- func (s *SnapshotV1) IsEmpty() bool
- func (s *SnapshotV1) Serialize() ([]byte, error)
- func (s *SnapshotV1) UpdateLastExecutionTime(key string, lastExecTime *time.Time)
- type VersionedSnapshot
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
type Metrics struct { Scope promutils.Scope SnapshotSaveErrCounter prometheus.Counter SnapshotCreationErrCounter prometheus.Counter }
type Persistence ¶
type Persistence interface { // Save Run(ctx context.Context) // Save saves the snapshot to the storage in a serialized form. Save(ctx context.Context, writer Writer, snapshot Snapshot) // Read reads the serialized snapshot from the storage and deserializes to its in memory format. Read(ctx context.Context, reader Reader) (Snapshot, error) }
Persistence allows to read and save the serialized form of the snapshot from a storage. Currently we have DB implementation for it.
func New ¶
func New(scope promutils.Scope, db repositoryInterfaces.SchedulerRepoInterface) Persistence
type Reader ¶
type Reader interface { // ReadSnapshot reads the snapshot from the reader ReadSnapshot(reader io.Reader) (Snapshot, error) }
Reader provides an interface to read the snapshot and deserialize it to its in memory format.
type Snapshot ¶
type Snapshot interface { // GetLastExecutionTime of the schedule given by the key GetLastExecutionTime(key string) *time.Time // UpdateLastExecutionTime of the schedule given by key to the lastExecTime UpdateLastExecutionTime(key string, lastExecTime *time.Time) // CreateSnapshot creates the snapshot of all the schedules and there execution times. Serialize() ([]byte, error) // BootstrapFrom bootstraps the snapshot from a byte array Deserialize(snapshot []byte) error // GetVersion gets the version number of snapshot written GetVersion() int // IsEmpty returns true if the snapshot contains no schedules IsEmpty() bool // Create an empty snapshot Create() Snapshot }
Snapshot used by the scheduler for creating, updating and reading snapshots of the schedules.
type SnapshotV1 ¶
type SnapshotV1 struct { // LastTimes map of the schedule name to last execution timestamp LastTimes map[string]*time.Time }
SnapshotV1 stores in the inmemory states of the schedules and there last execution timestamps. This map is created periodically from the jobstore of the gocron_wrapper and written to the DB. During bootup the serialized version of it is read from the DB and the schedules are initialized from it. V1 version so that in future if we add more fields for extending the functionality then this provides a backward compatible way to read old snapshots.
func (*SnapshotV1) Create ¶
func (s *SnapshotV1) Create() Snapshot
func (*SnapshotV1) Deserialize ¶
func (s *SnapshotV1) Deserialize(snapshot []byte) error
func (*SnapshotV1) GetLastExecutionTime ¶
func (s *SnapshotV1) GetLastExecutionTime(key string) *time.Time
func (*SnapshotV1) GetVersion ¶
func (s *SnapshotV1) GetVersion() int
func (*SnapshotV1) IsEmpty ¶
func (s *SnapshotV1) IsEmpty() bool
func (*SnapshotV1) Serialize ¶
func (s *SnapshotV1) Serialize() ([]byte, error)
func (*SnapshotV1) UpdateLastExecutionTime ¶
func (s *SnapshotV1) UpdateLastExecutionTime(key string, lastExecTime *time.Time)
type VersionedSnapshot ¶
VersionedSnapshot stores the version and gob serialized form of the snapshot Provides a read and write methods to serialize and deserialize the gob format of the snapshot. Including a version provides compatibility check
func (*VersionedSnapshot) ReadSnapshot ¶
func (s *VersionedSnapshot) ReadSnapshot(r io.Reader) (Snapshot, error)
func (*VersionedSnapshot) WriteSnapshot ¶
func (s *VersionedSnapshot) WriteSnapshot(w io.Writer, snapshot Snapshot) error