Skip to content

Commit

Permalink
s/RefreshInterval/StaticRefreshInterval/
Browse files Browse the repository at this point in the history
  • Loading branch information
matslina committed Jan 2, 2024
1 parent b723104 commit 708a1a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
29 changes: 14 additions & 15 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ var ErrNoActiveFeed = errors.New("no active feed found")

// Manager manages GTFS data.
type Manager struct {
RealtimeTTL time.Duration
RealtimeTimeout time.Duration
RealtimeMaxSize int
StaticTimeout time.Duration
StaticMaxSize int
RefreshInterval time.Duration
Downloader downloader.Downloader
RealtimeTTL time.Duration
RealtimeTimeout time.Duration
RealtimeMaxSize int
StaticTimeout time.Duration
StaticMaxSize int
StaticRefreshInterval time.Duration
Downloader downloader.Downloader

storage storage.Storage
}
Expand All @@ -47,13 +47,12 @@ type Manager struct {
// storage.
func NewManager(s storage.Storage) *Manager {
return &Manager{
RealtimeTTL: DefaultRealtimeTTL,
RealtimeTimeout: DefaultRealtimeTimeout,
RealtimeMaxSize: DefaultRealtimeMaxSize,
StaticTimeout: DefaultStaticTimeout,
StaticMaxSize: DefaultStaticMaxSize,
RefreshInterval: DefaultStaticRefreshInterval,
// TODO: s/RefreshInterval/StaticRefreshInterval/
RealtimeTTL: DefaultRealtimeTTL,
RealtimeTimeout: DefaultRealtimeTimeout,
RealtimeMaxSize: DefaultRealtimeMaxSize,
StaticTimeout: DefaultStaticTimeout,
StaticMaxSize: DefaultStaticMaxSize,
StaticRefreshInterval: DefaultStaticRefreshInterval,

Downloader: downloader.NewMemoryDownloader(),

Expand Down Expand Up @@ -161,7 +160,7 @@ func (m *Manager) Refresh(ctx context.Context) error {

errs := []error{}
for _, req := range requests {
if req.RefreshedAt.Before(time.Now().Add(-m.RefreshInterval)) {
if req.RefreshedAt.Before(time.Now().Add(-m.StaticRefreshInterval)) {
err = m.processRequest(req, feedsByHash)
if err != nil {
errs = append(errs, fmt.Errorf("refreshing feed at %s: %w", req.URL, err))
Expand Down
12 changes: 6 additions & 6 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func testManagerLoadWithRefresh(t *testing.T, strg storage.Storage) {
// Set a very low refresh interval, and manager will consider
// existing data stale. Refresh, and we'll see the feed 2
// data served.
m.RefreshInterval = time.Duration(0)
m.StaticRefreshInterval = time.Duration(0)
require.NoError(t, m.Refresh(context.Background()))
s2, err = m.LoadStaticAsync("a", server.Server.URL+"/static.zip", nil, when)
require.NoError(t, err)
Expand Down Expand Up @@ -583,7 +583,7 @@ func testManagerLoadWithRefresh(t *testing.T, strg storage.Storage) {

// Set a high refresh interval, and refresh. Server should not
// be hit.
m.RefreshInterval = time.Hour
m.StaticRefreshInterval = time.Hour
assert.NoError(t, m.Refresh(context.Background()))
assert.Equal(t, []string{"/static.zip", "/static.zip", "/static.zip"}, server.Requests)

Expand Down Expand Up @@ -648,10 +648,10 @@ func testManagerBrokenData(t *testing.T, strg storage.Storage) {
assert.NoError(t, m.Refresh(context.Background()))
assert.Equal(t, 3, len(server.Requests))

// Lower RefreshInterval and make the good zip
// Lower StaticRefreshInterval and make the good zip
// available. Refresh will download the new data.
server.Feeds["/static.zip"] = goodZip
m.RefreshInterval = time.Duration(0)
m.StaticRefreshInterval = time.Duration(0)
assert.NoError(t, m.Refresh(context.Background()))
assert.Equal(t, 4, len(server.Requests))

Expand All @@ -662,7 +662,7 @@ func testManagerBrokenData(t *testing.T, strg storage.Storage) {
require.NoError(t, err)
require.Equal(t, 1, len(stops))

// With RefreshInterval at 0, refresh will do a request each
// With StaticRefreshInterval at 0, refresh will do a request each
// time.
assert.NoError(t, m.Refresh(context.Background()))
assert.Equal(t, 5, len(server.Requests))
Expand Down Expand Up @@ -850,7 +850,7 @@ func testManagerRespectTimezones(t *testing.T, strg storage.Storage) {
}

// Verifies that manager can refresh a bunch of feeds according to the
// RefreshInterval.
// StaticRefreshInterval.
func testManagerRefreshFeeds(t *testing.T, strg storage.Storage) {
// TODO: write me
}
Expand Down

0 comments on commit 708a1a8

Please sign in to comment.