Skip to content

Commit

Permalink
Merge pull request #4481 from omnivore-app/jacksonh/exporter-break
Browse files Browse the repository at this point in the history
Make sure the exporter breaks
  • Loading branch information
jacksonh authored Nov 2, 2024
2 parents 22e46bf + 58a404b commit b7958fd
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions packages/api/src/jobs/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { findActiveUser } from '../services/user'
import { logger } from '../utils/logger'
import { highlightToMarkdown } from '../utils/parser'
import { contentFilePath, createGCSFile } from '../utils/uploads'
import { batch } from 'googleapis/build/src/apis/batch'

export interface ExportJobData {
userId: string
Expand Down Expand Up @@ -224,8 +225,7 @@ export const exportJob = async (jobData: ExportJobData) => {
try {
// fetch data from the database
const batchSize = 20
let hasNext = false
do {
for (cursor = 0; cursor < itemCount; cursor += batchSize) {
const items = await searchLibraryItems(
{
from: cursor,
Expand All @@ -241,20 +241,11 @@ export const exportJob = async (jobData: ExportJobData) => {
const size = items.length
// write data to the csv file
if (size > 0) {
const nextCursor = await uploadToBucket(
userId,
items,
cursor,
size,
archive
)
if (nextCursor == cursor) {
break
}
cursor = nextCursor
hasNext = size === batchSize
await uploadToBucket(userId, items, cursor, size, archive)
} else {
break
}
} while (hasNext)
}
} finally {
// Finalize the archive
await archive.finalize()
Expand Down

0 comments on commit b7958fd

Please sign in to comment.