Documentation ¶
Overview ¶
Package cron implements the database.Model interface for the Cron entity. The Cron entity allows for build's to be submitted on a defined schedule.
Index ¶
- func InitEvent(dis event.Dispatcher) queue.InitFunc
- func LoadRelations(loaders *database.Loaders, cc ...*Cron) error
- func Model(cc []*Cron) func(int) database.Model
- func SelectBuild(col string, opts ...query.Option) query.Query
- type Batcher
- type Build
- func (b *Build) Bind(mm ...database.Model)
- func (b *Build) Endpoint(uri ...string) string
- func (b *Build) IsZero() bool
- func (b *Build) JSON(addr string) map[string]interface{}
- func (b *Build) Primary() (string, int64)
- func (b *Build) SetPrimary(_ int64)
- func (b *Build) Values() map[string]interface{}
- type BuildStore
- type Cron
- type Event
- type Form
- type Schedule
- type Store
- func (s *Store) All(opts ...query.Option) ([]*Cron, error)
- func (s *Store) Bind(mm ...database.Model)
- func (s *Store) Create(authorId int64, name string, sched Schedule, m manifest.Manifest) (*Cron, error)
- func (s *Store) Delete(id int64) error
- func (s *Store) Get(opts ...query.Option) (*Cron, error)
- func (s *Store) Index(vals url.Values, opts ...query.Option) ([]*Cron, database.Paginator, error)
- func (s *Store) Invoke(c *Cron) (*build.Build, error)
- func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error
- func (s *Store) New() *Cron
- func (s *Store) Paginate(page, limit int64, opts ...query.Option) (database.Paginator, error)
- func (s *Store) Update(id int64, name string, sched Schedule, m manifest.Manifest) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadRelations ¶
LoadRelations loads all of the available relations for the given Cron models using the given loaders available.
Types ¶
type Batcher ¶
type Batcher struct {
// contains filtered or unexported fields
}
Batcher provides a way of retrieving batches of cron jobs that are ready to be executed.
func NewBatcher ¶
NewBatcher returns a new Batcher using the given Store to retrieve cron jobs from, and setting the size of each batch to the given limit.
type Build ¶
type Build struct { ID int64 `db:"id"` CronID int64 `db:"cron_id"` BuildID int64 `db:"build_id"` CreatedAt time.Time `db:"created_at"` Cron *Cron `db:"-"` Build *build.Build `db:"-"` }
Build is the type that represents a build trigged via a cron job.
func (*Build) Bind ¶
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either Cron or build.Build.
func (*Build) JSON ¶
JSON implements the database.Model interface. This will return the JSON of the bound build.Build model.
func (*Build) SetPrimary ¶
SetPrimary implements the database.Model interface.
type BuildStore ¶
type BuildStore struct { database.Store // Cron is the bound Cron model. If not nil this will bind the Cron model to // any Build models that are created. If not nil this will append a WHERE // clause on the cron_id column for all SELECT queries performed. Cron *Cron // Builds is the bound build.Build model. If not nil this will bind the // build.Build model to any Build models that are created. If not nil this // will append a WHERE clause to the build_id column for all SELECT queries // performed. Build *build.Build }
BuildStore is the type for creating Build models in the database.
func NewBuildStore ¶
func NewBuildStore(db *sqlx.DB, mm ...database.Model) *BuildStore
NewBuildStore returns a new BuildStore for querying the cron_builds table. Each of the given models if bound to the returned BuildStore.
func (*BuildStore) Bind ¶
func (s *BuildStore) Bind(mm ...database.Model)
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either Cron or build.Build.
type Cron ¶
type Cron struct { ID int64 `db:"id"` UserID int64 `db:"user_id"` AuthorID int64 `db:"author_id"` NamespaceID sql.NullInt64 `db:"namespace_id"` Name string `db:"name"` Schedule Schedule `db:"schedule"` Manifest manifest.Manifest `db:"manifest"` PrevRun sql.NullTime `db:"prev_run"` NextRun time.Time `db:"next_run"` CreatedAt time.Time `db:"created_at"` Author *user.User `db:"-"` User *user.User `db:"-"` Namespace *namespace.Namespace `db:"-"` }
Cron is the type that represents a cron job that has been created by the user.
func FromContext ¶
FromContext returns the Cron model from the given context, if any.
func (*Cron) Bind ¶
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.
func (*Cron) Endpoint ¶
Endpoint returns the endpoint to the current Variable database, with the given URI parts appended to it.
func (*Cron) JSON ¶
JSON implements the database.Model interface. This will return a map with the current Cron values under each key. If any of the User, or Namespace bound models exist on the Cron, then the JSON representation of these models will be returned in the map, under the user, and namespace keys respectively.
func (*Cron) SetPrimary ¶
SetPrimary implements the database.Model interface.
type Form ¶
type Form struct { Crons *Store `schema:"-"` Cron *Cron `schema:"-"` Name string `schema:"name" json:"name"` Schedule Schedule `schema:"schedule" json:"schedule"` Manifest manifest.Manifest `schema:"manifest" json:"manifest"` }
Form is the type that represents input data for creating and editing a cron job.
func (Form) Fields ¶
Fields returns a map of fields for the current Form. This map will contain the Namespace, Name, Schedule, and Manifest fields of the current form.
type Schedule ¶
type Schedule uint
Schedule represents the schedule of the Cron. This will either be Daily, Weekly, or Monthly. Below is how the Cron schedules are handled,
Daily - This will trigger a Cron on the start of the next day Weekly - This will trigger a Cron on the start of the next week Monthly - This will trigger a Cron on the start of the next month
func (Schedule) Next ¶
Next returns the next time a schedule will occur. If Daily the start of the next day is returned. If Weekly the start of the next week is returned. If Monthly the start of the next month is returned.
func (*Schedule) Scan ¶
Scan scans the given interface value into a byte slice and will attempt to turn it into the correct Schedule value. If it success then it set's it on the current Schedule, otherwise an error is returned.
func (*Schedule) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON attempts to unmarshal the given byte slice as a JSON string, and checks to see if it is a valid schedule of either daily, weekly, or monthly.
func (*Schedule) UnmarshalText ¶
UnmarshalText takes the given byte slice, and attempts to map it to a known Schedule. If it is a known Schedule, then that the current Schedule is set to that, otherwise webutil.UnmarshalError is returned.
type Store ¶
type Store struct { database.Store // User is the bound user.User model. If not nil this will bind the // user.User model to any Cron models that are created. If not nil this // will append a WHERE clause on the user_id column for all SELECT queries // performed. User *user.User // Namespace is the bound namespace.Namespace model. If not nil this will // bind the namespace.Namespace model to any Variable models that are // created. If not nil this will append a WHERE clause on the namespace_id // column for all SELECT queries performed. Namespace *namespace.Namespace }
Store is the type for creating, modifying, and deleting Cron models in the database.
func NewStore ¶
NewStore returns a new Store for querying the cron table. Each of the given models is bound to the returned Store.
func (*Store) All ¶
All returns a slice of Variable models, applying each query.Option that is given. The namespace.WhereCollaborator option is applied to the *user.User bound database, and the database.Where option is applied to the *namespace.Namespace bound database.
func (*Store) Bind ¶
Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.
func (*Store) Create ¶
func (s *Store) Create(authorId int64, name string, sched Schedule, m manifest.Manifest) (*Cron, error)
Create will create a new Cron with the given name, schedule, and manifest.
func (*Store) Get ¶
All returns a single Cron model, applying each query.Option that is given. The namespace.WhereCollaborator option is applied to the *user.User bound database, and the database.Where option is applied to the *namespace.Namespace bound database.
func (*Store) Index ¶
Index returns the paginated results from the cron table depending on the values that are present in url.Values. Detailed below are the values that are used from the given url.Values,
name - This applies the database.Search query.Option using the value of key
func (*Store) Invoke ¶
Invoke will create a new build for the given Cron if the NextRun time is after the current time. This will add a tag to the created build detailing the name of the Cron, and it's schedule.
func (*Store) Load ¶
func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error
Load loads in a slice of Cron models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls Store.All under the hood, so any bound models will impact the models being loaded.