Skip to content
This repository was archived by the owner on Oct 31, 2026. It is now read-only.

feat: 改成无服务器架构 - #13

Merged
Laimuslime merged 1 commit into
mainfrom
serverless
Oct 29, 2026
Merged

Laimuslime merged 1 commit into
mainfrom
serverless

Conversation

@Laimuslime

Copy link
Copy Markdown
Member

为什么

线上现在要常驻两样东西:next start,以及 node-cron 拉起的 auto-crawler.js / auto-attribution.js(还有一台 systemd)。无服务器平台没有这种一直活着的进程,磁盘也不可写。

改成什么样

  • Web 仍然是 Next.js,部署到 Vercel 后每个 API 都是按需函数。
  • 爬虫和归属同步改成时间片。进度写在 settings(crawler:cursor、attribution:cursor),调用结束进程就可以死。一轮爬虫跑完冷却 3 小时,归属同步冷却 30 分钟。
  • 调度有两条路:
    • vercel.json 里每天一次的 Cron(Hobby 计划更密会被拒)。
    • .github/workflows/serverless-jobs.yml 每 10 分钟推进最多 8 分钟。配 DATABASE_URL 即可;或者只配 SITE_ORIGIN + CRON_SECRET,去打 /api/cron/*。
  • /api/cron/crawl 和 /api/cron/attribution 用 CRON_SECRET 鉴权,没配密钥就 401。
  • 管理后台改站点写入 site:config,不再依赖可写的 wikitdb.config.js。爬虫日志写入 logs:crawler。
  • Prisma 客户端挂在 globalThis 上,Vercel 上自动补 connection_limit=1。限速在配了 Upstash 时跨实例共享。
  • wikit 全站备份留在 GitHub Actions(要二进制和磁盘),产物上传 artifact。函数里调用会直接跳过。
  • 宿主机 systemctl 删帖机器人在 VERCEL=1 时返回 501,改用已有的 BotAccount 扫描。

上线前要配

  • DATABASE_URL(连接池地址)
  • CRON_SECRET(至少 16 字符)
  • 仓库 Secret:DATABASE_URL,可选 WIKIDOT_BOT_USER / WIKIDOT_BOT_PASS
  • 可选:UPSTASH_REDIS_REST_URL / UPSTASH_REDIS_REST_TOKEN

npm run worker 还在,但跑完当前这一轮就退出,不要再交给 PM2 守护。

Stop keeping node-cron and systemd processes alive. Crawl and attribution
now run as short slices with cursors in Postgres, triggered by Vercel Cron
or GitHub Actions. Site config and crawler logs live in the database so a
read-only filesystem still works.
Comment thread jobs/crawler.js
const $parentPost = $parentContainer.children('.post').first();
parentId = ($parentPost.attr('id') || '').replace('post-', '');
}
let author = '未知用户';
Comment thread jobs/crawler.js
let pageId = null;
const idMatch = html.match(/pageId\s*[:=]\s*['"]?(\d+)['"]?/i) || html.match(/page_id\s*[:=]\s*['"]?(\d+)['"]?/i);
if (idMatch) pageId = idMatch[1];
if (!pageId) { success = true; return; }
@Laimuslime
Laimuslime merged commit d594390 into main Oct 29, 2026
2 checks passed
Laimuslime added a commit that referenced this pull request Oct 29, 2026
Undo the serverless merge (PR #13) and return main to e7e794e,
the last commit by lestday233.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant