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

refactor path.win32 normalitation #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
54 changes: 29 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@ import { initialize } from "./cluster.js"
import { getMongoConnection, getPostgresConnection } from './db.js'
import cliProgress from 'cli-progress'
import { setTimeout } from 'node:timers/promises'
import path from 'path'

const mongoDB = await getMongoConnection()
const postgresDB = await getPostgresConnection()
const ITEMS_PER_PAGE = 4000
const CLUSTER_SIZE = 99
const TASK_FILE = new URL('./background-task.js', import.meta.url).pathname

// Obtener la ruta absoluta y normalizarla usando path.win32 para compatibilidad con Windows
let TASK_FILE = new URL('./background-task.js', import.meta.url).pathname
if (process.platform === 'win32') {
TASK_FILE = path.win32.normalize(TASK_FILE.replace(/^\//, ''))
}

// console.log(`there was ${await postgresDB.students.count()} items on Postgres, deleting all...`)
await postgresDB.students.deleteAll()

async function* getAllPagedData(itemsPerPage, page = 0) {

const data = mongoDB.students.find().skip(page).limit(itemsPerPage)
const items = await data.toArray()
if (!items.length) return

yield items

yield* getAllPagedData(itemsPerPage, page += itemsPerPage)
}

Expand All @@ -34,7 +39,7 @@ progress.start(total, 0);
let totalProcessed = 0
const cp = initialize(
{
backgroundTaskFile: TASK_FILE,
backgroundTaskFile: TASK_FILE, // Usar la ruta corregida aquí
clusterSize: CLUSTER_SIZE,
amountToBeProcessed: total,
async onMessage(message) {
Expand All @@ -49,7 +54,6 @@ const cp = initialize(
console.log(`total on MongoDB ${total} and total on PostGres ${insertedOnSQLite}`)
console.log(`are the same? ${total === insertedOnSQLite ? 'yes' : 'no'}`)
process.exit()

}
}
)
Expand All @@ -58,4 +62,3 @@ await setTimeout(1000)
for await (const data of getAllPagedData(ITEMS_PER_PAGE)) {
cp.sendToChild(data)
}