Memstack Automation Cron Scheduler 标志

Memstack Automation Cron Scheduler

社区
cwinvestments
memstack-automation-cron-scheduler

Use this skill when the user says 'cron job', 'scheduled task', 'run every', 'cron expression', 'recurring job', or needs production-grade scheduled jobs with overlap prevention, monitoring, and structured logging. Do NOT use for n8n workflows or event-driven webhooks.

概览

发布者cwinvestments
代码仓库memstack
技能名称memstack-automation-cron-scheduler
星标数
425
复刻数
45
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 cwinvestments 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Memstack Automation Cron Scheduler AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/cwinvestments/memstack/tree/master/skills/automation/cron-scheduler
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cwinvestments/memstack.git /tmp/memstack
mkdir -p .claude/skills
cp -r /tmp/memstack/skills/automation/cron-scheduler .claude/skills/memstack-automation-cron-scheduler
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Memstack Automation Cron Scheduler,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Memstack Automation Cron Scheduler。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Memstack Automation Cron Scheduler 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Cron Scheduler: Building scheduled job...

Builds production-grade scheduled jobs with cron syntax, timezone handling, overlap prevention, health checks, monitoring, alerting, and structured logging.

Activation

When this skill activates, output:

Cron Scheduler: Building scheduled job...

Then execute the protocol below.

Context Guard

ContextStatus
User says "cron job", "scheduled task", "run every"ACTIVE
User says "cron expression" or "recurring job"ACTIVE
User needs a time-based scheduled task with monitoringACTIVE
User wants a visual n8n workflowDORMANT: use n8n Workflow Builder
User wants an event-driven webhookDORMANT: use Webhook Designer

Common Mistakes

MistakeWhy It's Wrong
"No overlap prevention"If a job takes 10 min and runs every 5 min, you get concurrent executions corrupting data.
"Ignore timezones"Cron defaults to server timezone. Midnight UTC ≠ midnight local. Always set TZ explicitly.
"No monitoring"Silent job failures are invisible. You won't know it broke until users complain.
"Log to stdout only"Stdout disappears on restart. Use structured logging with persistence.
"Run as root"Principle of least privilege. Run jobs under a dedicated service account.

Protocol

Step 1: Gather Job Requirements

If the user hasn't provided details, ask:

  1. Task: what does the job do? (sync data, send emails, clean up, generate reports)
  2. Schedule: how often? (every 5 min, hourly, daily at 2 AM, weekly)
  3. Duration: how long does a typical run take?
  4. Timezone: which timezone matters? (UTC, user's local, business hours)
  5. Platform: where does this run? (server crontab, cloud function, Docker, Kubernetes)
  6. Failure mode: what happens if it fails? (retry, alert, skip until next run)

Step 2: Write the Cron Expression

Cron syntax (5-field standard):

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-7, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *

Common schedule reference:

ScheduleExpressionNotes
Every minute* * * * *Testing only: too aggressive for production
Every 5 minutes*/5 * * * *Good for near-real-time sync
Every 15 minutes*/15 * * * *Light polling
Every hour0 * * * *At minute 0 of every hour
Every 6 hours0 */6 * * *4x daily
Daily at 2 AM UTC0 2 * * *Maintenance window
Daily at 9 AM ET0 14 * * *14:00 UTC = 9:00 AM ET (EST, adjust for DST)
Weekdays at 8 AM0 8 * * 1-5Monday through Friday
Weekly (Sunday midnight)0 0 * * 0Weekly cleanup
Monthly (1st at midnight)0 0 1 * *Monthly reports
Quarterly (Jan/Apr/Jul/Oct 1st)0 0 1 1,4,7,10 *Quarterly processing

Timezone handling:

bash
# System crontab, set TZ per job
CRON_TZ=America/New_York
0 9 * * * /path/to/job.sh    # Runs at 9 AM Eastern (handles DST)

# Or set in the crontab header
TZ=UTC
typescript
// Node.js (node-cron), explicit timezone
import cron from 'node-cron';

cron.schedule('0 9 * * *', () => {
  runDailyReport();
}, {
  timezone: 'America/New_York'
});

Step 3: Implement Overlap Prevention

Lock-based approach (recommended):

typescript
import { acquireLock, releaseLock } from './lockService';

async function runJob() {
  const lockKey = 'job:daily-report';
  const lockTTL = 3600; // seconds, must exceed max job duration

  const acquired = await acquireLock(lockKey, lockTTL);
  if (!acquired) {
    console.log('Job already running: skipping this execution');
    return;
  }

  try {
    await executeJobLogic();
  } finally {
    await releaseLock(lockKey);
  }
}

Lock implementations by platform:

PlatformLock MethodTTL Support
RedisSET key value NX EX ttlYes
PostgreSQLpg_advisory_lock(id)Session-based
File systemflock or PID fileManual cleanup
DynamoDBConditional put with TTLYes
KubernetesCronJob concurrencyPolicy: ForbidBuilt-in

PID file approach (simple servers):

bash
#!/bin/bash
PIDFILE="/tmp/myjob.pid"

if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") 2>/dev/null; then
    echo "Job already running (PID $(cat $PIDFILE))"
    exit 0
fi

echo $$ > "$PIDFILE"
trap "rm -f $PIDFILE" EXIT

# Job logic here

Step 4: Structured Logging

typescript
interface JobLog {
  job: string;
  runId: string;        // Unique per execution
  phase: 'start' | 'progress' | 'complete' | 'error';
  timestamp: string;
  durationMs?: number;
  itemsProcessed?: number;
  error?: string;
  metadata?: Record<string, any>;
}

function logJob(entry: JobLog): void {
  console.log(JSON.stringify(entry));
}

// Usage
const runId = crypto.randomUUID();
const start = Date.now();

logJob({ job: 'daily-report', runId, phase: 'start', timestamp: new Date().toISOString() });

try {
  const result = await executeJobLogic();
  logJob({
    job: 'daily-report', runId, phase: 'complete',
    timestamp: new Date().toISOString(),
    durationMs: Date.now() - start,
    itemsProcessed: result.count
  });
} catch (error) {
  logJob({
    job: 'daily-report', runId, phase: 'error',
    timestamp: new Date().toISOString(),
    durationMs: Date.now() - start,
    error: error.message
  });
  throw error;
}

Step 5: Monitoring & Alerting

Health check pattern: heartbeat:

typescript
// After successful job completion, ping a health check URL
async function pingHealthCheck(url: string): Promise<void> {
  await fetch(url); // Services: Cronitor, Healthchecks.io, Better Uptime
}

// The monitoring service alerts if it doesn't receive a ping within the expected window

Alert conditions:

ConditionSeverityAction
Job didn't run (missed heartbeat)CriticalPage on-call
Job failed (error thrown)HighSlack + email alert
Job duration > 2x normalWarningSlack notification
Job processed 0 items (expected >0)WarningReview logs
Job overlap detected (lock contention)InfoLog, investigate if frequent

Job history table (for dashboard):

sql
CREATE TABLE job_runs (
  id           SERIAL PRIMARY KEY,
  job_name     VARCHAR(100) NOT NULL,
  run_id       UUID         NOT NULL,
  status       VARCHAR(20)  NOT NULL, -- 'success' | 'failure' | 'skipped'
  started_at   TIMESTAMPTZ  NOT NULL,
  completed_at TIMESTAMPTZ,
  duration_ms  INTEGER,
  items_count  INTEGER,
  error        TEXT,
  metadata     JSONB
);

CREATE INDEX idx_job_runs_name_started ON job_runs(job_name, started_at DESC);

Step 6: Production Checklist

Before deploying:

  • Cron expression tested with crontab.guru
  • Timezone explicitly set (never rely on server default)
  • Overlap prevention implemented (lock or concurrency policy)
  • Structured logging with run IDs
  • Health check / heartbeat URL configured
  • Alert rules set for: missed run, failure, slow run
  • Graceful shutdown handling (finish current item, don't corrupt)
  • Environment variables for all config (no hardcoded values)
  • Job runs under dedicated service account (not root)
  • Tested with realistic data volume

Maintenance:

  • Review job duration trends monthly (creeping duration = scaling issue)
  • Clean up job history older than 90 days
  • Verify health check alerts with a test failure quarterly

Output Format

markdown
# Cron Job: [Job Name]

## Schedule
- **Expression:** [cron expression]
- **Timezone:** [TZ]
- **Frequency:** [Human-readable]
- **Expected duration:** [X minutes]

## Job Logic
[What the job does, step by step]

## Implementation
[Code with overlap prevention, logging, error handling]

## Monitoring
- **Health check:** [URL or service]
- **Alerts:** [Alert conditions]
- **Dashboard:** [Where to view job history]

## Production Checklist
[Completed checklist from Step 6]

Completion

Cron Scheduler: Complete!

Job: [Name]
Schedule: [Expression] ([timezone])
Overlap prevention: [Lock method]
Monitoring: [Health check service]
Alerts: [Count] conditions configured

Next steps:
1. Implement the job using the code templates above
2. Test the cron expression at crontab.guru
3. Deploy with overlap prevention and structured logging
4. Set up health check monitoring
5. Verify the first 3 runs succeed, then check weekly

Level History

  • Lv.1: Base: Cron syntax guide with 12 common schedules, timezone handling (crontab + Node.js), overlap prevention (Redis lock, PID file, K8s ConcurrencyPolicy), structured logging with run IDs, heartbeat monitoring pattern, alert conditions (5 severities), job history table, production deployment checklist. (Origin: MemStack Pro v3.2, Mar 2026)

常见问题

Memstack Automation Cron Scheduler AI 技能有什么作用?

Use this skill when the user says 'cron job', 'scheduled task', 'run every', 'cron expression', 'recurring job', or needs production-grade scheduled jobs with overlap prevention, monitoring, and structured logging. Do NOT use for n8n workflows or event-driven webhooks.

为什么在 TypingMind 中使用 Memstack Automation Cron Scheduler?

因为您只需安装一次,就能搭配任何模型使用。Memstack Automation Cron Scheduler 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Memstack Automation Cron Scheduler?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/cwinvestments/memstack/tree/master/skills/automation/cron-scheduler。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Memstack Automation Cron Scheduler?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Memstack Automation Cron Scheduler 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Memstack Automation Cron Scheduler 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Memstack Automation Cron Scheduler AI 技能免费吗?

是的。cwinvestments 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇