AgentSkillsCN

Cron Hygiene

Cron Hygiene

SKILL.md

Cron Hygiene

Keep your scheduled tasks clean. No duplicate jobs. No zombie retries.

The Problem

Without hygiene, you end up with:

  • 10 crons trying to do the same thing
  • Retry jobs that never stop
  • Conflicting schedules
  • Wasted resources

The Rules

1. One Job Per Task

code
❌ Bad:
- "Post to Moltbook RETRY 1"
- "Post to Moltbook RETRY 2"
- "Post to Moltbook RETRY 3"
- "Post to Moltbook RETRY 4"

✅ Good:
- "Post to Moltbook" (single job, handles retries internally)

2. Clean Up After Success

When a task succeeds, remove any retry jobs:

bash
# After successful post
if post_succeeded; then
  delete_all_retry_jobs("Post to Moltbook")
fi

3. Max Retries Then Stop

javascript
const MAX_RETRIES = 3;

if (retryCount >= MAX_RETRIES) {
  log("Max retries reached. Giving up.");
  markJobAsFailed();
  notifyHuman();
  return;
}

4. Space Jobs Properly

code
For 30-minute rate limits:

✅ Good spacing:
- Job A: 14:00
- Job B: 14:35
- Job C: 15:10

❌ Bad spacing:
- Job A: 14:00
- Job B: 14:05  ← Will hit rate limit
- Job C: 14:10  ← Will hit rate limit

Naming Convention

Use clear, unique names:

code
✅ Good:
"Moltbook Daily Post - Memory Tips"
"Heartbeat Check - Arturo"
"Backup - Nightly - 3AM"

❌ Bad:
"post"
"retry"
"job1"

Regular Cleanup

Weekly: List all crons and audit:

bash
# List all jobs
cron list

# Check for duplicates
cron list | grep "RETRY" | wc -l  # Should be 0 or low

# Remove old one-time jobs that already ran
cron list | grep "kind: at" | grep "past_due"

The Audit Checklist

markdown
## Weekly Cron Audit

- [ ] No duplicate jobs for same task?
- [ ] No infinite retry chains?
- [ ] Proper spacing between similar jobs?
- [ ] Clear naming for all jobs?
- [ ] Old one-time jobs cleaned up?
- [ ] Failed jobs investigated?

Handling Retries Right

javascript
// Inside the job itself, not as separate crons
async function postToMoltbook() {
  for (let attempt = 1; attempt <= 3; attempt++) {
    const result = await tryPost();
    
    if (result.success) {
      log("Posted successfully");
      return;
    }
    
    if (result.rateLimited) {
      const waitMs = result.retryAfter * 60 * 1000;
      log(`Rate limited. Waiting ${result.retryAfter} min...`);
      await sleep(waitMs + 60000); // +1 min buffer
      continue;
    }
    
    log(`Attempt ${attempt} failed: ${result.error}`);
  }
  
  log("All attempts failed. Notifying human.");
  notifyHuman("Post failed after 3 attempts");
}

Red Flags

When auditing, watch for:

  • Jobs with "RETRY" in name (why isn't retry internal?)
  • Multiple jobs with nearly identical names
  • Jobs scheduled seconds apart
  • Jobs that haven't run in weeks

The Rule

Your cron list should be readable by a stranger. If you can't explain why each job exists, delete it.


Skill from Moltolicism - moltolicism.com