func setupPrefetchTicker() *time.Ticker {
	if config.Prefetch != nil {
		duration, err := getPrefetchDuration(config.Prefetch.Cron, time.Now())
		if err == nil && duration > 0 {
			ticker := time.NewTicker(duration)  
			log.Printf("The prefetching routine will be run on %v", time.Now().Add(duration))
			go func() {
				lastTimeInvoked := time.Time{}
				for range ticker.C {
					if time.Since(lastTimeInvoked) > time.Second {
						prefetchPackages()
						lastTimeInvoked = time.Now()
						now := time.Now()
						duration, err := getPrefetchDuration(config.Prefetch.Cron, time.Now())
						if err == nil && duration > 0 {
							ticker.Reset(duration)  
							log.Printf("On %v the prefetching routine will be run again", now.Add(duration))
						} else {
							ticker.Stop()
							log.Printf("Prefetching disabled")
						}
					}  
				}
			}()
			return ticker
		}
		log.Printf("Prefetching is disabled")
		return nil
	}
	log.Fatalf("Called setupPrefetchTicker with config.Prefetch uninitialized")
	return nil
}
Setups the prefetching ticker
package main
import (
	"fmt"
	"log"
	"os"
	"path"
	"strings"
	"time"
	"github.com/gorhill/cronexpr"
)
func getPrefetchDuration(cronStr string, from time.Time) (time.Duration, error) {
	cron, err := cronexpr.Parse(cronStr)
	if err != nil {
		return time.Duration(0), err  
	}
	nextTick := cron.Next(from)
	if !nextTick.IsZero() {
		duration := nextTick.Sub(from)
		return duration, err
	}
	return time.Duration(0), fmt.Errorf("there is no next tick")
}