From 5176c73b4bfea6c1c30c11bd79b874d6c5153c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Di=C3=B3genes=20Fernandes?= Date: Thu, 27 Feb 2025 11:14:58 -0300 Subject: [PATCH] deploy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DiĆ³genes Fernandes deploy Signed-off-by: DiĆ³genes Fernandes --- search/worker/package-lock.json | 4 +-- search/worker/scripts/feed-data-r2.js | 35 ++++++++------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/search/worker/package-lock.json b/search/worker/package-lock.json index 06e82b5..d71659f 100644 --- a/search/worker/package-lock.json +++ b/search/worker/package-lock.json @@ -1,12 +1,12 @@ { "name": "registry-ui-search", - "version": "0.0.1", + "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "registry-ui-search", - "version": "0.0.1", + "version": "0.0.0", "dependencies": { "@neondatabase/serverless": "^0.9.4", "postgres": "^3.4.5" diff --git a/search/worker/scripts/feed-data-r2.js b/search/worker/scripts/feed-data-r2.js index a16f37b..0a175a5 100755 --- a/search/worker/scripts/feed-data-r2.js +++ b/search/worker/scripts/feed-data-r2.js @@ -1,18 +1,20 @@ // This script is used to retrieve data generated by `go run generate.go` at backend folder. // It will generate registry data that will be used by this script to feed into wrangler dev folder, mimicking a R2 bucket. // This script expects data will be at /tmp/registry. -import { createRequire } from "module"; -const require = createRequire(import.meta.url); const fs = require('fs'); const path = require('path'); const { exec } = require('node:child_process'); -const BATCH_SIZE = 10 -const DIR_PATH = '/tmp/registry'; +const directoryPath = '/tmp/registry'; -const putObject = (directoryPath) => (filename) => { - return new Promise((resolve) => { - const realFilePath = path.join(directoryPath, filename); +fs.readdir(directoryPath, { recursive: true }, (err, files) => { + if (err) { + console.error('Error reading directory:', err); + return; + } + + files.forEach(fileName => { + const realFilePath = path.join(directoryPath, fileName); const r2Name = realFilePath.replace(directoryPath, ""); const cmd = `npx wrangler r2 object put registry-ui-api${r2Name} --file ${realFilePath} --local` @@ -21,23 +23,6 @@ const putObject = (directoryPath) => (filename) => { console.log(stdout); console.error(stderr); }); - resolve(); - }); -} -const run = async () => { - fs.readdir(DIR_PATH, { recursive: true }, async (err, files) => { - if (err) { - console.error('Error reading directory:', err); - return; - } - - let i = 1; - while (files.length) { - await Promise.all(files.splice(0, BATCH_SIZE).map(putObject(DIR_PATH))); - i++; - } }); -} - -await run() +});