DEV Community

zongkai sun
zongkai sun

Posted on

How One Node.js Loop Publishes to 7 Platforms Without Duplicates

How One Node.js Loop Publishes to 7 Platforms Without Duplicates

I'm Xiaosuanshi (小算师) — a free site that serves daily horoscopes for all 12 Western zodiac signs and 12 Chinese zodiac animals, fully automated. This is part of my "building in public" series where I open up the pipeline instead of just the product.

One scheduler, seven platforms

The site publishes to Tumblr, Bluesky, Mastodon, Blogger, dev.to, YouTube and Telegraph every day. All of them are driven by one Node.js loop that wakes up every 10 minutes:

// socialDaily.js — 每个平台一个 UTC 小时槽位(串行错峰)
const HOURS = {
  pin: 0, tumblr: 1, bsky: 2, mastodon: 4,
  blogger: 5, devto: 6, youtube: 8, telegraph: 12,
};
// 每 10 分钟一轮 watch():到点 + 当天没发过 → 才发
if (h === HOURS.bsky && !day.bsky) {
  await publishPlatform(t, 'bsky', 'Bluesky', bluesky);
}
Enter fullscreen mode Exit fullscreen mode

Publishing platforms sequentially on fixed UTC hours does two things for free:

  • Rate limits are never hit because only one platform posts at a time,
  • Duplicate posts are impossible because each platform checks its own "already done today" flag. ## Why idempotency is the real feature PM2 restarts, network timeouts and server crashes happen. Without idempotent publishing, a crash after the API call but before the state save means the same post goes out twice. The guard is boring and effective:
// 幂等:发布前查当天记录,已发直接跳过
async function publishPlatform(date, key, label, publisher) {
  const day = loadRecord()[date] || {};
  if (day[key]) return log(`${label} 当天已发布,跳过`);
  const ok = await publisher.publishDate(date, cfg);
  day[key] = { done: true, posted: ok };
  saveRecord(record);
}
Enter fullscreen mode Exit fullscreen mode

This tiny pattern — "check record, act, save record" — is the only reason the pipeline survives restarts without spamming followers. Every platform wrapper implements the same publishDate(date) interface, so adding a new one is ~40 lines.

Today's reading

Year of the Rabbit — Sunday, September 13, 2026 (Chinese zodiac animal)
Rabbit, today's a day for relaxation. Focus on your well-being.
Love

Quality time with your partner is key. A gentle touch can say a lot.
Career

Avoid taking on too much. Focus on what's most important.
Lucky number: 3

Full reading: Xiaosuanshi

One post a day from this project. All content is AI-generated for entertainment. Follow if you build in public too.

Top comments (0)