HW14 Completed

hw12_13_14_15_calendar
tiburon 2020-11-23 17:25:21 +03:00
parent 63c008f963
commit 04241cb809
2 changed files with 7 additions and 2 deletions

View File

@ -36,7 +36,7 @@ func New(conf Config) Scheduler {
} }
func (s *Scheduler) Start(ctx context.Context) error { func (s *Scheduler) Start(ctx context.Context) error {
fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit) }, 1*time.Minute) fetcher := riseOnTick(ctx, s.Logger, func() interface{} { return worker(ctx, s.CalendarAPI, s.Rabbit, s.Logger) }, 1*time.Minute)
go func() { go func() {
for { for {
select { select {

View File

@ -37,7 +37,7 @@ func riseOnTick(ctx context.Context, log logger.Interface, fn func() interface{}
return valueStream return valueStream
} }
func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit) error { func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit, log logger.Interface) error {
cli, err := private.NewClient(calendarAPI.Address, calendarAPI.Port) cli, err := private.NewClient(calendarAPI.Address, calendarAPI.Port)
if err != nil { if err != nil {
return err return err
@ -56,5 +56,10 @@ func worker(ctx context.Context, calendarAPI config.Server, rb *rabbit.Rabbit) e
return err return err
} }
} }
resp2, err := cli.PurgeOldEvents(ctx, &private.PurgeReq{OlderThenDays: 365})
if err != nil {
return err
}
log.Infof("Scheduler successfully purges %s events from storage", resp2.Qty)
return nil return nil
} }