-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lazy_load option to preserve existing behaviorImplements the file…
…s event producer to populate the cacheto be consistent with the other sources.Default behavior enables a static unbounded cache so all the objectsare preloaded, and do not expire.If a lru cache is explicitly defined, it will be used instead.Setting lazy_load=true will disable preload and operate inlazy load backed by cache mode. Addressing feedback Address https://github.com/prebid/prebid-server/pull/1411/files#r476907655 Address https://github.com/prebid/prebid-server/pull/1411/files#r476926516 Fixed bug uncovered by new unit test.
- Loading branch information
Showing
11 changed files
with
200 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package files | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/golang/glog" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/stored_requests" | ||
"github.com/prebid/prebid-server/stored_requests/backends/file_fetcher" | ||
"github.com/prebid/prebid-server/stored_requests/events" | ||
) | ||
|
||
type fileEventProducer struct { | ||
invalidations chan events.Invalidation | ||
saves chan events.Save | ||
} | ||
|
||
func (f *fileEventProducer) Saves() <-chan events.Save { | ||
return f.saves | ||
} | ||
func (f *fileEventProducer) Invalidations() <-chan events.Invalidation { | ||
return f.invalidations | ||
} | ||
|
||
// NewFilesLoader returns an EventProducer preloaded with all the stored reqs+imps | ||
func NewFilesLoader(cfg config.FileFetcherConfig) events.EventProducer { | ||
fp := &fileEventProducer{ | ||
saves: make(chan events.Save, 1), | ||
invalidations: make(chan events.Invalidation), | ||
} | ||
if fetcher, err := file_fetcher.NewFileFetcher(cfg.Path); err == nil { | ||
reqData, impData, errs := fetcher.(stored_requests.Fetcher).FetchAllRequests(context.Background()) | ||
if len(reqData) > 0 || len(impData) > 0 { | ||
fp.saves <- events.Save{ | ||
Requests: reqData, | ||
Imps: impData, | ||
} | ||
} | ||
for _, err := range errs { | ||
glog.Warning(err.Error()) | ||
} | ||
} else { | ||
glog.Warningf("Failed to prefetch files from %s: %v", cfg.Path, err) | ||
close(fp.saves) | ||
} | ||
return fp | ||
} |
Oops, something went wrong.