diff --git a/Dockerfile.scraper b/Dockerfile.scraper index 491913b..6e183d2 100644 --- a/Dockerfile.scraper +++ b/Dockerfile.scraper @@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y libsqlite3-dev && rm -rf /var/lib/apt/l RUN cargo install --path . 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 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 DB_PATH=/db/db.db -# Cron scraper -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"] +CMD ["bun", "/bin/scraper", "cron"] diff --git a/bun.lockb b/bun.lockb index 3eaba39..1c05176 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/scraper/cli.ts b/scraper/cli.ts index 8223973..d4bcdc8 100644 --- a/scraper/cli.ts +++ b/scraper/cli.ts @@ -4,9 +4,14 @@ import { scrapDiaProducts } from "../link-scrapers/dia.js"; import { scrapJumboProducts } from "../link-scrapers/jumbo.js"; import { auto } from "./auto.js"; import { downloadList, getProduct } from "./scrap.js"; +import Cron from "croner"; if (process.argv[2] === "auto") { await auto(); +} else if (process.argv[2] === "cron") { + Cron("0 2 * * *", () => { + auto(); + }); } else if (process.argv[2] === "scrap-carrefour-links") { await scrapCarrefourProducts(); } else if (process.argv[2] === "scrap-dia-links") { diff --git a/scraper/package.json b/scraper/package.json index 4399980..5a6ff62 100644 --- a/scraper/package.json +++ b/scraper/package.json @@ -13,6 +13,7 @@ "dependencies": { "@aws-sdk/client-s3": "^3.478.0", "@aws-sdk/lib-storage": "^3.478.0", + "croner": "^8.0.0", "date-fns": "^3.0.6", "db-datos": "workspace:^", "drizzle-orm": "^0.29.1",