feat(notify): 通知拆成「新作品」与「异常」两个开关,异常默认开
问题:cookie 过期导致任务失败,但没有任何通知。查下来不是代码问题 —— notify_enabled 在两个任务上都是 False,而它默认就是关的,事件(run_failed) 也确实生成了,只卡在最后一道闸门。 但那个默认值是错的。代码里的理由是「一条任务列表都推到一个群会很快变吵,所以默认静默」, 这个理由对新作品成立(可能每轮都有),对失败不成立:一次登录态失效意味着这个任务事实上 已经死了,而你不会知道,直到某天发现数据停在几周前。最该被告知的就是这种情况。 现在拆开: - notify_enabled —— 推送新作品,可能每轮都有,默认关 - notify_failures —— 推送异常(登录失效/运行失败/没抓到数据),默认开 事件按开关过滤(build_run_message):只勾了「新作品」的任务不该因为一次失败被推消息, 反之亦然,否则拆开开关就没有意义。已有任务由 _ensure_columns 补上 notify_failures=1, 所以会自动开始收到异常推送。 列名 notify_enabled 是历史遗留(它早先是唯一的通知开关),语义已收窄为「新作品」, 用注释写明,不做列重命名 —— 那需要单独的迁移,不值为一个内部工具做。
This commit is contained in:
@@ -118,6 +118,8 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
const [enableComments, setEnableComments] = useState(true)
|
||||
const [maxComments, setMaxComments] = useState('50')
|
||||
const [notifyEnabled, setNotifyEnabled] = useState(false)
|
||||
// 异常推送默认开:失败意味着这个任务从此默默采不到东西,而你不会知道。
|
||||
const [notifyFailures, setNotifyFailures] = useState(true)
|
||||
const [targets, setTargets] = useState('')
|
||||
|
||||
// Reset the form whenever the dialog is (re)opened. For a new task the
|
||||
@@ -142,6 +144,7 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
String(task?.max_comments_count ?? settings?.values['collect.default_max_comments'] ?? 50),
|
||||
)
|
||||
setNotifyEnabled(task?.notify_enabled ?? false)
|
||||
setNotifyFailures(task?.notify_failures ?? true)
|
||||
setTargets(task ? task.targets.map((t) => t.raw_value || t.external_id).join('\n') : '')
|
||||
}, [open, task, settings])
|
||||
|
||||
@@ -185,6 +188,7 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
run_timeout_seconds: 3600,
|
||||
enabled: true,
|
||||
notify_enabled: notifyEnabled,
|
||||
notify_failures: notifyFailures,
|
||||
targets: targetList,
|
||||
}
|
||||
|
||||
@@ -455,24 +459,55 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-2 rounded-md border border-cyber-border-subtle bg-cyber-bg-tertiary/40 p-3">
|
||||
<Checkbox
|
||||
id="notify-enabled"
|
||||
checked={notifyEnabled}
|
||||
onCheckedChange={(checked) => setNotifyEnabled(checked === true)}
|
||||
/>
|
||||
<div className="space-y-0.5">
|
||||
<label
|
||||
htmlFor="notify-enabled"
|
||||
className="text-xs font-mono text-cyber-text-primary cursor-pointer"
|
||||
>
|
||||
推送企业微信通知
|
||||
</label>
|
||||
<p className="text-[10px] font-mono text-cyber-text-muted">
|
||||
仅在本任务**采集失败 / 登录态失效**或**发现新作品**时推送,
|
||||
一轮只发一条汇总。需先在监控页配置 Webhook 地址。
|
||||
</p>
|
||||
<div className="rounded-md border border-cyber-border-subtle bg-cyber-bg-tertiary/40 p-3 space-y-3">
|
||||
{/* 两类通知的性质完全不同,所以分成两个开关:
|
||||
异常低频且意味着任务已经停止工作 —— 默认开;
|
||||
新作品可能每轮都有 —— 默认关,否则会刷屏。 */}
|
||||
<div className="flex items-start gap-2">
|
||||
<Checkbox
|
||||
id="notify-failures"
|
||||
checked={notifyFailures}
|
||||
onCheckedChange={(checked) => setNotifyFailures(checked === true)}
|
||||
/>
|
||||
<div className="space-y-0.5">
|
||||
<label
|
||||
htmlFor="notify-failures"
|
||||
className="text-xs font-mono text-cyber-text-primary cursor-pointer"
|
||||
>
|
||||
推送异常通知(建议保持开启)
|
||||
</label>
|
||||
<p className="text-[10px] font-mono text-cyber-text-muted leading-relaxed">
|
||||
登录态失效、采集进程失败、一篇都没抓到时推送。
|
||||
<span className="text-cyber-neon-cyan">
|
||||
异常意味着这个任务从此默默采不到任何东西
|
||||
</span>
|
||||
—— 关掉的话你不会知道,直到某天发现数据停在几周前。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-2 border-t border-cyber-border-subtle pt-3">
|
||||
<Checkbox
|
||||
id="notify-enabled"
|
||||
checked={notifyEnabled}
|
||||
onCheckedChange={(checked) => setNotifyEnabled(checked === true)}
|
||||
/>
|
||||
<div className="space-y-0.5">
|
||||
<label
|
||||
htmlFor="notify-enabled"
|
||||
className="text-xs font-mono text-cyber-text-primary cursor-pointer"
|
||||
>
|
||||
推送新作品通知
|
||||
</label>
|
||||
<p className="text-[10px] font-mono text-cyber-text-muted leading-relaxed">
|
||||
发现新作品时推送。监控多个博主时可能每轮都有,容易刷屏,所以默认关闭。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="border-t border-cyber-border-subtle pt-2 text-[10px] font-mono text-cyber-text-muted">
|
||||
两者都是一轮只发一条汇总。需先在右上角「系统设置」里配置企业微信 Webhook 地址。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -56,8 +56,10 @@ export interface MonitorTask {
|
||||
enable_comments: boolean
|
||||
max_comments_count: number
|
||||
run_timeout_seconds: number
|
||||
/** Opt-in per task so one webhook does not get flooded. */
|
||||
/** 推送**新作品**。可能每轮都有,默认关以免刷屏。 */
|
||||
notify_enabled: boolean
|
||||
/** 推送**异常**(登录失效/运行失败/没抓到数据)。默认开。 */
|
||||
notify_failures: boolean
|
||||
/** Epoch milliseconds. */
|
||||
next_run_at: number | null
|
||||
last_run_at: number | null
|
||||
@@ -258,6 +260,7 @@ export interface TaskCreatePayload {
|
||||
run_timeout_seconds: number
|
||||
enabled: boolean
|
||||
notify_enabled: boolean
|
||||
notify_failures: boolean
|
||||
targets: string[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user