Documentation ¶
Index ¶
- Variables
- type DailyUsers
- func (r *DailyUsers) LastRun() time.Time
- func (r *DailyUsers) NewAccounts(tx *sql.Tx, day sql.NamedArg) (accounts []*emails.NewAccountData, err error)
- func (r *DailyUsers) NextRun() time.Time
- func (r *DailyUsers) Report() (err error)
- func (r *DailyUsers) Run() error
- func (r *DailyUsers) Scheduler(ts time.Time) (err error)
- func (r *DailyUsers) Shutdown() error
- type DailyUsersEmailer
Constants ¶
This section is empty.
Variables ¶
var (
ErrBeforeLastRun = errors.New("cannot schedule report before last run")
)
Functions ¶
This section is empty.
Types ¶
type DailyUsers ¶
type DailyUsers struct {
// contains filtered or unexported fields
}
The DailyUsers report is generated once per day at the specified schedule using a sleep-based cron mechanism. When the report is generated an email is sent to the Rotational admins with the report contents.
func NewDailyUsers ¶
func NewDailyUsers(emailer DailyUsersEmailer) (report *DailyUsers, err error)
func (*DailyUsers) LastRun ¶
func (r *DailyUsers) LastRun() time.Time
Get the last time the daily report was run.
func (*DailyUsers) NewAccounts ¶ added in v0.7.0
func (r *DailyUsers) NewAccounts(tx *sql.Tx, day sql.NamedArg) (accounts []*emails.NewAccountData, err error)
NewAccounts generates the new accounts report as an additional item to the daily users report. It is kept in a separate function because it does not follow the replicated SQL pattern and so needs to be parallelized for it to be effective.
func (*DailyUsers) NextRun ¶
func (r *DailyUsers) NextRun() time.Time
Get the timestamp that the next report should run (within 15 minutes).
func (*DailyUsers) Report ¶
func (r *DailyUsers) Report() (err error)
Runs the daily users report and emails the admins. If an error is returned from report it is expected to be fatal; all other errors should simply be logged.
func (*DailyUsers) Run ¶
func (r *DailyUsers) Run() error
Run the daily users report tool which checks if it needs to run every 15 minutes (e.g. the poll interval) and if the next run time is after the current time it runs the report, otherwise it continues to sleep.
func (*DailyUsers) Scheduler ¶
func (r *DailyUsers) Scheduler(ts time.Time) (err error)
Scheduler determines if the report needs to be run and if it does, it runs the report and schedules the next run (updating the lastRun timestamp). We expect the ts to be passed in from the ticker at run; but if a zero-valued timestamp is passed in, then the current timestamp is used. If this method returns an error it is assumed to be fatal (e.g. so bad it should shut down the reporting tool).
func (*DailyUsers) Shutdown ¶
func (r *DailyUsers) Shutdown() error
Shutdown the report runner gracefully; this will ensure that a report that is currently being generated will finish before shutting down.
type DailyUsersEmailer ¶
type DailyUsersEmailer interface {
SendDailyUsers(*emails.DailyUsersData) error
}