This repository has been archived on 2022-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
dataupdater/internal/cron/tasks/task.go

30 lines
601 B
Go

package tasks
import (
"github.com/go-pg/pg/v10"
"github.com/pkg/errors"
"sync"
"time"
"github.com/tribalwarshelp/cron/internal/cron/queue"
)
type task struct {
db *pg.DB
queue queue.Queue
cachedLocations sync.Map
}
func (t *task) loadLocation(timezone string) (*time.Location, error) {
val, ok := t.cachedLocations.Load(timezone)
if ok {
return val.(*time.Location), nil
}
location, err := time.LoadLocation(timezone)
if err != nil {
return nil, errors.Wrap(err, "task.loadLocation")
}
t.cachedLocations.Store(timezone, location)
return location, nil
}