correr cron dentro de scraper

This commit is contained in:
Cat /dev/Nulo 2024-01-11 21:08:43 -03:00
parent a438eec238
commit 66fc8767ef
4 changed files with 8 additions and 6 deletions

View file

@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y libsqlite3-dev && rm -rf /var/lib/apt/l
RUN cargo install --path . RUN cargo install --path .
FROM docker.io/oven/bun:1-slim FROM docker.io/oven/bun:1-slim
RUN apt-get update && apt-get install -y busybox-static sqlite3 && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y sqlite3 && rm -rf /var/lib/apt/lists/*
# Scraper # Scraper
COPY --from=build /tmp/cli.build.js /bin/scraper COPY --from=build /tmp/cli.build.js /bin/scraper
@ -25,8 +25,4 @@ COPY --from=rs-build /usr/local/cargo/bin/scraper-rs /usr/local/bin/scraper-rs
ENV NODE_ENV=production ENV NODE_ENV=production
ENV DB_PATH=/db/db.db ENV DB_PATH=/db/db.db
# Cron scraper CMD ["bun", "/bin/scraper", "cron"]
RUN mkdir -p /var/spool/cron/crontabs \
&& printf "0 2 * * * bun /bin/scraper auto\n" > /var/spool/cron/crontabs/root
CMD ["busybox", "crond", "-f", "-l2"]

BIN
bun.lockb

Binary file not shown.

View file

@ -4,9 +4,14 @@ import { scrapDiaProducts } from "../link-scrapers/dia.js";
import { scrapJumboProducts } from "../link-scrapers/jumbo.js"; import { scrapJumboProducts } from "../link-scrapers/jumbo.js";
import { auto } from "./auto.js"; import { auto } from "./auto.js";
import { downloadList, getProduct } from "./scrap.js"; import { downloadList, getProduct } from "./scrap.js";
import Cron from "croner";
if (process.argv[2] === "auto") { if (process.argv[2] === "auto") {
await auto(); await auto();
} else if (process.argv[2] === "cron") {
Cron("0 2 * * *", () => {
auto();
});
} else if (process.argv[2] === "scrap-carrefour-links") { } else if (process.argv[2] === "scrap-carrefour-links") {
await scrapCarrefourProducts(); await scrapCarrefourProducts();
} else if (process.argv[2] === "scrap-dia-links") { } else if (process.argv[2] === "scrap-dia-links") {

View file

@ -13,6 +13,7 @@
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.478.0", "@aws-sdk/client-s3": "^3.478.0",
"@aws-sdk/lib-storage": "^3.478.0", "@aws-sdk/lib-storage": "^3.478.0",
"croner": "^8.0.0",
"date-fns": "^3.0.6", "date-fns": "^3.0.6",
"db-datos": "workspace:^", "db-datos": "workspace:^",
"drizzle-orm": "^0.29.1", "drizzle-orm": "^0.29.1",