Modulo makers3d desarrollado con codex V 0.0.1

This commit is contained in:
Ryuk Mike
2026-07-29 23:58:58 +02:00
commit 2bedf7cbb7
171 changed files with 29421 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
FROM node:22-bookworm-slim AS build
WORKDIR /app
COPY package.json tsconfig.base.json ./
COPY apps/worker/package.json apps/worker/package.json
RUN npm install
COPY . .
RUN npm run build -w @makers3d/worker
FROM node:22-bookworm-slim
WORKDIR /app
COPY --from=build /app/package.json ./
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/apps/worker/dist ./apps/worker/dist
ENV NODE_ENV=production
CMD ["node", "apps/worker/dist/index.js"]
+19
View File
@@ -0,0 +1,19 @@
{
"name": "@makers3d/worker",
"version": "0.1.0",
"type": "module",
"main": "dist/index.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node dist/index.js",
"dev": "tsx watch src/index.ts",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"pg": "^8.16.3"
},
"devDependencies": {
"@types/pg": "^8.15.6"
}
}
+54
View File
@@ -0,0 +1,54 @@
import { Pool } from "pg";
const databaseUrl = process.env.DATABASE_URL;
if (!databaseUrl) {
throw new Error("DATABASE_URL is required");
}
const pool = new Pool({ connectionString: databaseUrl });
async function processJobs(): Promise<void> {
const client = await pool.connect();
try {
await client.query("begin");
const result = await client.query<{
id: string;
type: string;
}>(
`
select id, type
from jobs
where status = 'pending'
order by created_at asc
limit 5
for update skip locked
`
);
for (const job of result.rows) {
await client.query(`update jobs set status = 'processing', attempts = attempts + 1, updated_at = now() where id = $1`, [job.id]);
await client.query(`update jobs set status = 'done', updated_at = now() where id = $1`, [job.id]);
console.log(`Processed job ${job.id} (${job.type})`);
}
await client.query("commit");
} catch (error) {
await client.query("rollback");
console.error("Worker cycle failed", error);
} finally {
client.release();
}
}
async function loop() {
while (true) {
await processJobs();
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}
loop().catch((error) => {
console.error(error);
process.exit(1);
});
+10
View File
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"declaration": true
},
"include": ["src/**/*.ts"]
}