Skip to content

Commit

Permalink
Merge pull request #341 from Financial-Times/ACC1347
Browse files Browse the repository at this point in the history
ACC-1347 Create metrics for syndication article and video downloads
  • Loading branch information
asugar13 authored Jan 12, 2022
2 parents bf9c325 + c972523 commit 9655fdf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ft-next-syndication-api",
"description": "Next Syndication API",
"version": "0.38.6",
"version": "0.40.0",
"private": true,
"dependencies": {
"@financial-times/n-es-client": "3.0.0",
Expand Down
40 changes: 23 additions & 17 deletions server/controllers/download-by-content-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,40 @@ module.exports = exports = async (req, res, next) => {

prepareDownloadResponse(res, content);

if (dl.downloadAsArchive) {
dl.on('error', (err, httpStatus) => {
log.error('DOWNLOAD_ARCHIVE_ERROR', {
event: 'DOWNLOAD_ARCHIVE_ERROR',
error: err.stack || err
});

res.status(httpStatus || 500).end();
let articleOrArchive = dl.downloadAsArchive ? 'Archive' : 'Article';

log.count(`${articleOrArchive.toLowerCase()}-download-start`);

dl.on('error', (err) => {
log.error(`DOWNLOAD_${articleOrArchive.toUpperCase()}_ERROR`, {
event: `DOWNLOAD_${articleOrArchive.toUpperCase()}_ERROR`,
error: err.stack || err
});
log.count(`${articleOrArchive.toLowerCase()}-download-error`);
res.status(500).end();
});

dl.on('complete', (state, status) => {
if (state === 'complete') {
log.count(`${articleOrArchive.toLowerCase()}-download-complete`);
}
res.status(status);
});

dl.on('cancelled', () => {
next();
});

if (articleOrArchive === 'Archive') {
dl.on('end', () => {
log.debug(`DownloadArchiveEnd => ${content.id} in ${Date.now() - dl.START}ms`);

if (dl.cancelled !== true) {
res.end();

next();
}
});

dl.on('complete', (state, status) => {
res.status(status);
});

dl.on('cancelled', () => {
next();
});

dl.pipe(res);

await dl.appendAll();
Expand Down
2 changes: 2 additions & 0 deletions server/lib/download/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = exports = class ArticleDownload extends Archiver {

if (this.endCalled !== true) {
this.endCalled = true;
this.emit('cancelled');
}
}

Expand Down Expand Up @@ -113,6 +114,7 @@ module.exports = exports = class ArticleDownload extends Archiver {
return this.file;
}
catch (error) {
this.emit('error', error);
log.error('convertArticle', {
contentId: content.id,
error
Expand Down

0 comments on commit 9655fdf

Please sign in to comment.