<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>技术实录 on NFY</title><link>https://ningop.com/categories/%E6%8A%80%E6%9C%AF%E5%AE%9E%E5%BD%95/</link><description>Recent content in 技术实录 on NFY</description><generator>Hugo</generator><language>zh</language><lastBuildDate>Sun, 06 Sep 2026 20:04:05 +0800</lastBuildDate><atom:link href="https://ningop.com/categories/%E6%8A%80%E6%9C%AF%E5%AE%9E%E5%BD%95/index.xml" rel="self" type="application/rss+xml"/><item><title>Notion KB与Cron集成：从Hermes Gateway到System Crontab的迁移实录</title><link>https://ningop.com/posts/2026-09-06-notion-kb-cron-integration-migration/</link><pubDate>Sun, 06 Sep 2026 19:45:00 +0800</pubDate><guid>https://ningop.com/posts/2026-09-06-notion-kb-cron-integration-migration/</guid><description>&lt;p>&lt;img alt="featured" loading="lazy" src="https://ningop.com/images/posts/2026-09-06-notion-kb-cron-integration-migration.jpg">&lt;/p>
&lt;h2 id="问题背景hermes-cron-gateway-的-systemd-限制">问题背景：Hermes Cron Gateway 的 systemd 限制&lt;/h2>
&lt;p>Hermes 的 cron 系统依赖 &lt;code>systemd-run --user --scope&lt;/code> 启动隔离 worker。当前环境（容器/权限受限）报错：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Restart-safe cron worker dispatch failed: cannot create restart-safe systemd scope for gateway child: systemd-run --user --scope is unavailable
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>导致 18 个 Hermes cron jobs 全部失败，无法执行任何定时任务。&lt;/p>
&lt;h2 id="解决方案迁移到系统级-crontab">解决方案：迁移到系统级 crontab&lt;/h2>
&lt;p>直接编写 &lt;code>/root/.hermes/cron/system-crontab&lt;/code> 并 &lt;code>crontab /root/.hermes/cron/system-crontab&lt;/code> 安装，绕过 Hermes gateway，由系统 cron 直接调用 Python 脚本。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 安装&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">crontab /root/.hermes/cron/system-crontab
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 查看&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">crontab -l
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="核心脚本">核心脚本&lt;/h2>
&lt;h3 id="1-notion-kb-每日全量同步-sync-notion-kbpy">1. Notion KB 每日全量同步 (&lt;code>sync-notion-kb.py&lt;/code>)&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="ch">#!/usr/bin/env python3&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 使用 Notion API 直连，拉取「人生规划」页面及其子页面&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 环境变量：NOTION_API_KEY&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 输出：/root/.hermes/kb/notion/*.md + LIVE-INDEX.txt + UNIFIED-INDEX.txt&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>运行时间：&lt;code>0 3 * * *&lt;/code> (每日 03:00)&lt;/li>
&lt;li>结果：33/33 页面成功，LIVE-INDEX 93 行，UNIFIED-INDEX 427 行&lt;/li>
&lt;li>日志：&lt;code>/root/.hermes/cron/system-logs/sync-notion-kb.log&lt;/code>&lt;/li>
&lt;/ul>
&lt;h3 id="2-双向写回模块-writeback_notionpy">2. 双向写回模块 (&lt;code>writeback_notion.py&lt;/code>)&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 支持三种模式&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">writeback&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">page_id&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">title&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">content&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">mode&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;date-toggle&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># date-toggle: 同一天同标题创建 toggle 块，后续追加到 children&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># append: 直接追加&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># overwrite: 覆盖&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>4 个 preset 配置：&lt;/p></description></item></channel></rss>