diff --git a/projects/archiver/src/tasks/front/index.ts b/projects/archiver/src/tasks/front/index.ts index 1f32931b9f..7c640ea491 100644 --- a/projects/archiver/src/tasks/front/index.ts +++ b/projects/archiver/src/tasks/front/index.ts @@ -1,16 +1,14 @@ import { Handler } from 'aws-lambda' -import { unnest } from 'ramda' import { attempt, hasFailed } from '../../../../backend/utils/try' -import { frontPath, Image } from '../../../common' -import { getImagesFromFront } from '../image/helpers/media' +import { frontPath } from '../../../common' +import { handleAndNotifyOnError } from '../../services/task-handler' import { getFront } from '../../utils/backend-client' +import { Bucket, ONE_WEEK, upload } from '../../utils/s3' import { IssueTaskOutput } from '../issue' -import { Bucket, upload, ONE_WEEK } from '../../utils/s3' -import { handleAndNotifyOnError } from '../../services/task-handler' type FrontTaskInput = IssueTaskOutput export interface FrontTaskOutput extends IssueTaskOutput { - images: Image[] + frontId: string } export const handler: Handler< FrontTaskInput, @@ -29,8 +27,6 @@ export const handler: Handler< console.log(`succesfully download front ${frontId}`, maybeFront) - const images: Image[] = unnest(getImagesFromFront(maybeFront)) - const frontUpload = await attempt( upload( frontPath(publishedId, frontId), @@ -51,7 +47,7 @@ export const handler: Handler< return { issuePublication, issue: { ...issue, fronts: publishedFronts }, - images, + frontId, fronts: remainingFronts, remainingFronts: remainingFronts.length, message: `Succesfully published ${frontId}`, diff --git a/projects/archiver/src/tasks/image/index.ts b/projects/archiver/src/tasks/image/index.ts index 00c23c3de9..87423c459d 100644 --- a/projects/archiver/src/tasks/image/index.ts +++ b/projects/archiver/src/tasks/image/index.ts @@ -2,10 +2,15 @@ import { Handler } from 'aws-lambda' import { unnest } from 'ramda' import { attempt, hasFailed } from '../../../../backend/utils/try' import { Image, ImageSize, imageSizes } from '../../../common' -import { getAndUploadColours, getAndUploadImage } from './helpers/media' +import { + getAndUploadColours, + getAndUploadImage, + getImagesFromFront, +} from './helpers/media' import pAll = require('p-all') import { FrontTaskOutput } from '../front' import { handleAndNotifyOnError } from '../../services/task-handler' +import { getFront } from '../../utils/backend-client' type ImageTaskInput = FrontTaskOutput export interface ImageTaskOutput extends Omit { @@ -16,9 +21,20 @@ export const handler: Handler< ImageTaskInput, ImageTaskOutput > = handleAndNotifyOnError( - async ({ issuePublication, issue, images, ...params }) => { + async ({ issuePublication, issue, frontId, ...params }) => { const { publishedId } = issue + const maybeFront = await getFront(publishedId, frontId) + + if (hasFailed(maybeFront)) { + console.error(JSON.stringify(attempt)) + throw new Error(`Could not download front ${frontId}`) + } + + console.log(`succesfully download front ${frontId}`, maybeFront) + + const images: Image[] = unnest(getImagesFromFront(maybeFront)) + const imagesWithSizes: [Image, ImageSize][] = unnest( images.map(image => imageSizes.map((size): [Image, ImageSize] => [image, size]), @@ -56,6 +72,7 @@ export const handler: Handler< return { issuePublication, issue, + frontId, ...params, failedColours, failedImages,