Skip to content

Commit

Permalink
only do video caching if we don't already have a videoCacheKey (prebi…
Browse files Browse the repository at this point in the history
…d#2143)

* only do video caching if we don't already have a videoCacheKey

* log error for missing vastUrl when videoCacheKey specified
  • Loading branch information
snapwich authored and dluxemburg committed Jul 17, 2018
1 parent 5f3f3e0 commit 499cbbb
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,33 @@ function addBidToAuction(auctionInstance, bidResponse) {
}

// Video bids may fail if the cache is down, or there's trouble on the network.
function tryAddVideoBid(auctionInstance, bidResponse, bidRequest, vastUrl) {
function tryAddVideoBid(auctionInstance, bidResponse, bidRequest) {
let addBid = true;
if (config.getConfig('cache.url')) {
store([bidResponse], function(error, cacheIds) {
if (error) {
utils.logWarn(`Failed to save to the video cache: ${error}. Video bid must be discarded.`);

doCallbacksIfTimedout(auctionInstance, bidResponse);
} else {
bidResponse.videoCacheKey = cacheIds[0].uuid;
if (!vastUrl) {
bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey);
if (!bidResponse.videoCacheKey) {
addBid = false;
store([bidResponse], function (error, cacheIds) {
if (error) {
utils.logWarn(`Failed to save to the video cache: ${error}. Video bid must be discarded.`);

doCallbacksIfTimedout(auctionInstance, bidResponse);
} else {
bidResponse.videoCacheKey = cacheIds[0].uuid;
if (!bidResponse.vastUrl) {
bidResponse.vastUrl = getCacheUrl(bidResponse.videoCacheKey);
}
// only set this prop after the bid has been cached to avoid early ending auction early in bidsBackAll
bidRequest.doneCbCallCount += 1;
addBidToAuction(auctionInstance, bidResponse);
auctionInstance.bidsBackAll();
}
// only set this prop after the bid has been cached to avoid early ending auction early in bidsBackAll
bidRequest.doneCbCallCount += 1;
addBidToAuction(auctionInstance, bidResponse);
auctionInstance.bidsBackAll();
}
});
} else {
});
} else if (!bidResponse.vastUrl) {
utils.logError('videoCacheKey specified but not required vastUrl for video bid');
addBid = false;
}
}
if (addBid) {
addBidToAuction(auctionInstance, bidResponse);
}
}
Expand All @@ -256,7 +264,7 @@ export const addBidResponse = createHook('asyncSeries', function(adUnitCode, bid
let bidResponse = getPreparedBidForAuction({adUnitCode, bid, bidRequest, auctionId});

if (bidResponse.mediaType === 'video') {
tryAddVideoBid(auctionInstance, bidResponse, bidRequest, bid.vastUrl);
tryAddVideoBid(auctionInstance, bidResponse, bidRequest);
} else {
addBidToAuction(auctionInstance, bidResponse);
}
Expand Down

0 comments on commit 499cbbb

Please sign in to comment.