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

Fail Early #64

Merged
merged 5 commits into from
Sep 5, 2023
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
1,948 changes: 1,036 additions & 912 deletions ingest-delete/package-lock.json

Large diffs are not rendered by default.

2,249 changes: 1,153 additions & 1,096 deletions ingest-image/package-lock.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion ingest-image/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export default class Task {
const md = {
Bucket: record.s3.bucket.name,
// Key Decode: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-tutorial.html
Key: decodeURIComponent(record.s3.object.key.replace(/\+/g, ' '))
Key: decodeURIComponent(record.s3.object.key.replace(/\+/g, ' ')),
errors: []
};
console.log(`New file detected in ${md.Bucket}: ${md.Key}`);
md.FileName = `${path.parse(md.Key).name}${path.parse(md.Key).ext.toLowerCase()}`;
Expand Down Expand Up @@ -118,9 +119,20 @@ export default class Task {

const mimetype = mime.lookup(tmp_path);
md = await this.enrich_meta_data(md, exif_data, mimetype);

try {
await this.sharp_meta(md);
} catch (err) {
md.errors.push('Sharp could not open provided image');
}

await this.save_image(md);
}

async sharp_meta(md) {
return await sharp(path.join(this.tmp_dir, md.FileName)).metadata();
}

async save_image(md) {
try {
const imageAttempt = (await fetcher(this.ANIML_API_URL, {
Expand Down
29 changes: 12 additions & 17 deletions ingest-zip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ export default async function handler() {
params.set(param.Name, param.Value);
}

const head = await s3.send(new S3.HeadObjectCommand({
Bucket: task.Bucket,
Key: task.Key
}));

await pipeline(
(await s3.send(new S3.GetObjectCommand({
Bucket: task.Bucket,
Expand Down Expand Up @@ -79,9 +74,9 @@ export default async function handler() {
}

zip.close();

const now = new Date();
let input = {
const input = {
_id: batch,
total: total,
uploadComplete: now
Expand All @@ -90,7 +85,7 @@ export default async function handler() {
if (total === 0) {
console.log('ok - no image files to process');
input.processingStart = now,
input.processingEnd = now
input.processingEnd = now;
}

await fetcher(params.get(`/api/url-${STAGE}`), {
Expand All @@ -116,11 +111,11 @@ export default async function handler() {
await fetcher(params.get(`/api/url-${STAGE}`), {
query: UPDATE_BATCH_QUERY,
variables: {
input: {
_id: batch,
processingStart: new Date()
}
}
input: {
_id: batch,
processingStart: new Date()
}
}
});

const prezip = new StreamZip.async({
Expand Down Expand Up @@ -166,10 +161,10 @@ export default async function handler() {
await fetcher(params.get(`/api/url-${STAGE}`), {
query: UPDATE_BATCH_QUERY,
variables: {
input: {
_id: batch,
ingestionComplete: new Date()
}
input: {
_id: batch,
ingestionComplete: new Date()
}
}
});
} catch (err) {
Expand Down
Loading