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

feat: prevent re-converting scenes that were already converted during the last 3 days #119

Merged
merged 1 commit into from
May 1, 2024
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
4 changes: 2 additions & 2 deletions consumer-server/src/adapters/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function createCloudStorageAdapter({ config }: Pick<AppComponents,

const s3 = new S3Client({ region, endpoint: bucketEndpoint })

async function getFiles(prefix: string): Promise<string[]> {
async function getFiles(prefix: string): Promise<{ key: string, lastModified: Date | undefined}[]> {
const list = await s3.send(
new ListObjectsV2Command({
Bucket: bucket,
Expand All @@ -22,7 +22,7 @@ export async function createCloudStorageAdapter({ config }: Pick<AppComponents,

return (
list.Contents?.filter((file) => !file.Key?.endsWith('output.txt')).map(
(file) => `${bucketEndpoint}/${bucket}/${file.Key}`
(file) => ({ key: `${bucketEndpoint}/${bucket}/${file.Key}`, lastModified: file.LastModified })
) || []
)
}
Expand Down
23 changes: 23 additions & 0 deletions consumer-server/src/logic/message-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ export async function createMessageProcesorComponent({
return
}

const alreadyUploadedFiles = await storage.getFiles(`${base}/LOD/Sources/${message.entity.entityTimestamp.toString()}`)

if (!!alreadyUploadedFiles.length) {
const lastUploadDate = alreadyUploadedFiles.reduce((acc, file) => {
if (!file.lastModified) return acc
return file.lastModified > acc ? file.lastModified : acc
}, new Date(0))

const currentDate = new Date()
const diff = currentDate.getTime() - lastUploadDate.getTime()
const diffDays = diff / (1000 * 3600 * 24)
if (diffDays < 3) {
logger.debug('Skipping process since it was already processed within the last 3 days', {
entityId,
base,
lastUploadDate: lastUploadDate.toISOString(),
currentDate: currentDate.toISOString()
})
await queue.deleteMessage(receiptMessageHandle)
return
}
}

logger.info('Processing scene deployment', {
entityId,
base,
Expand Down
2 changes: 1 addition & 1 deletion consumer-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export type MessageProcessorComponent = {

export type StorageComponent = {
storeFiles(filePaths: string[], prefix: string): Promise<string[]>
getFiles(prefix: string): Promise<string[]>
getFiles(prefix: string): Promise<{ key: string, lastModified: Date | undefined}[]>
deleteFailureDirectory(pointer: string): Promise<void>
}

Expand Down
Loading