Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move image download to image task #769

Merged
merged 1 commit into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions projects/archiver/src/tasks/front/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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),
Expand All @@ -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}`,
Expand Down
21 changes: 19 additions & 2 deletions projects/archiver/src/tasks/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FrontTaskOutput, 'images'> {
Expand All @@ -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]),
Expand Down Expand Up @@ -56,6 +72,7 @@ export const handler: Handler<
return {
issuePublication,
issue,
frontId,
...params,
failedColours,
failedImages,
Expand Down