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

Scorpio — Saturday, September 5, 2026 (Western zodiac sign)
Today brings a learning opportunity for Scorpio. Whether it is a new skill, a different perspective or an honest piece of feedback, treat it as a gift rather than a setback. Curiosity opens a door that ambition could not.
Love

In love, Scorpio feels magnetic today. If single, an unexpected connection sparks through a friend or shared interest. If attached, a small honest gesture deepens your bond more than a grand one would.
Career

Results come slower than Scorpio would like today — and that is exactly what a strategic mind should expect. Keep quality high, keep communication open, and let the work speak. Impatience is the only real risk.
Health: Sleep quality is Scorpio's lever today. Dim the lights an hour earlier, leave the phone outside the bedroom, and guard those hours like an appointment. One good night rearranges your whole week.
Lucky number: 6

Full reading → View Scorpio on xiaosuanshi.com

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

Top comments (0)