feat(monitor): 超级编导自动追加,任务设置里按间隔补新作品
任务编辑里新增「自动从超级编导追加新作品」(抖音 + 作品模式才有): - 每 N 分钟(默认 2 小时)按**发布时间**查一次数据中心,把这段时间新发布、 还没在任务里的作品追加进去;已有的不会重复。 - start_time/end_time 实测按发布时间过滤,所以老活动里今天才发的作品也能 收到 —— 按活动创建时间筛会整批漏掉。 - 查询窗口首尾重叠 1 小时,兜住数据中心的索引延迟;失败时 last_at 不动, 恢复后这段时间的作品仍在窗口里,只把调度钟按 30 分钟退避重试。 - 同步跑在后台任务里,不阻塞采集调度。 Co-Authored-By: Claude <[email protected]>
This commit is contained in:
@@ -21,7 +21,7 @@ import {
|
||||
} from '@/components/ui/select'
|
||||
import { useCreateTask, useSettings, useUpdateTask } from '@/hooks/useMonitor'
|
||||
import { useCurrentPlatform } from '@/hooks/usePlatform'
|
||||
import { describeSchedule } from '@/lib/monitorFormat'
|
||||
import { describeSchedule, formatDateTime } from '@/lib/monitorFormat'
|
||||
import type {
|
||||
MonitorMode,
|
||||
MonitorTask,
|
||||
@@ -59,6 +59,18 @@ const SCHEDULE_MODE_OPTIONS: Array<{ value: ScheduleMode; label: string }> = [
|
||||
|
||||
const HOURS = Array.from({ length: 24 }, (_, hour) => hour)
|
||||
|
||||
// 超级编导自动追加的检查频率。默认 2 小时 —— 分发作品陆续发布,查太勤只是多打
|
||||
// 第三方接口,查太慢则新作品要等很久才进监控。
|
||||
const SUPERDIR_INTERVAL_OPTIONS = [
|
||||
{ value: '30', label: '30 分钟' },
|
||||
{ value: '60', label: '1 小时' },
|
||||
{ value: '120', label: '2 小时' },
|
||||
{ value: '180', label: '3 小时' },
|
||||
{ value: '360', label: '6 小时' },
|
||||
{ value: '720', label: '12 小时' },
|
||||
{ value: '1440', label: '1 天' },
|
||||
]
|
||||
|
||||
/**
|
||||
* Above this many works per run, warn about the request volume.
|
||||
*
|
||||
@@ -123,6 +135,8 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
const [enableComments, setEnableComments] = useState(true)
|
||||
const [maxComments, setMaxComments] = useState('50')
|
||||
const [notifyEnabled, setNotifyEnabled] = useState(false)
|
||||
const [superdirAuto, setSuperdirAuto] = useState(false)
|
||||
const [superdirInterval, setSuperdirInterval] = useState('120')
|
||||
// 异常推送默认开:失败意味着这个任务从此默默采不到东西,而你不会知道。
|
||||
const [notifyFailures, setNotifyFailures] = useState(true)
|
||||
const [targets, setTargets] = useState('')
|
||||
@@ -153,6 +167,8 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
)
|
||||
setNotifyEnabled(task?.notify_enabled ?? false)
|
||||
setNotifyFailures(task?.notify_failures ?? true)
|
||||
setSuperdirAuto(task?.superdir_auto_enabled ?? false)
|
||||
setSuperdirInterval(String(task?.superdir_auto_interval_minutes ?? 120))
|
||||
setTargets(task ? task.targets.map((t) => t.raw_value || t.external_id).join('\n') : '')
|
||||
setAppendTargets('')
|
||||
}, [open, task, settings])
|
||||
@@ -185,6 +201,8 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
const clockIncomplete =
|
||||
scheduleMode !== 'interval' &&
|
||||
(scheduleHours.length === 0 || (scheduleMode === 'weekly' && scheduleDays.length === 0))
|
||||
// 超级编导只接抖音分发,追加进去的又只能是作品 id —— 只有这一种任务能用。
|
||||
const superdirEligible = platform === 'dy' && mode === 'note'
|
||||
const canSubmit =
|
||||
name.trim().length > 0 && mergedTargets.length > 0 && !pending && !clockIncomplete
|
||||
|
||||
@@ -209,6 +227,9 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
enabled: true,
|
||||
notify_enabled: notifyEnabled,
|
||||
notify_failures: notifyFailures,
|
||||
// 非抖音/作品模式时后端会拒绝,所以这里按平台和模式清掉,别让旧状态带上去。
|
||||
superdir_auto_enabled: superdirEligible ? superdirAuto : false,
|
||||
superdir_auto_interval_minutes: Number(superdirInterval),
|
||||
targets: mergedTargets,
|
||||
}
|
||||
|
||||
@@ -511,6 +532,69 @@ export function TaskEditorDialog({ open, onOpenChange, task }: TaskEditorDialogP
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{superdirEligible && (
|
||||
<div className="rounded-md border border-cyber-border-subtle bg-cyber-bg-tertiary/40 p-3 space-y-2">
|
||||
<div className="flex items-start gap-2">
|
||||
<Checkbox
|
||||
id="superdir-auto"
|
||||
checked={superdirAuto}
|
||||
onCheckedChange={(checked) => setSuperdirAuto(checked === true)}
|
||||
/>
|
||||
<div className="space-y-0.5">
|
||||
<label
|
||||
htmlFor="superdir-auto"
|
||||
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-text-secondary">新发布</span>
|
||||
的作品自动加到本任务;已有的不会重复。需要先在「设置」里配好超级编导 Token。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{superdirAuto && (
|
||||
<div className="flex flex-wrap items-center gap-2 pl-6">
|
||||
<span className="text-[10px] font-mono text-cyber-text-secondary">
|
||||
检查间隔
|
||||
</span>
|
||||
<Select value={superdirInterval} onValueChange={setSuperdirInterval}>
|
||||
<SelectTrigger className="h-7 w-28 text-xs">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{SUPERDIR_INTERVAL_OPTIONS.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<span className="text-[10px] font-mono text-cyber-text-muted">
|
||||
保存后立即检查一次,之后按间隔跑
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isEdit && task?.superdir_auto_enabled && (
|
||||
<p className="pl-6 text-[10px] font-mono text-cyber-text-muted">
|
||||
上次检查 {formatDateTime(task.superdir_auto_last_at)},新增{' '}
|
||||
<span className="text-cyber-neon-cyan">
|
||||
{task.superdir_auto_last_added ?? 0}
|
||||
</span>{' '}
|
||||
条
|
||||
</p>
|
||||
)}
|
||||
{isEdit && task?.superdir_auto_last_error && (
|
||||
<p className="pl-6 text-[10px] font-mono text-cyber-neon-pink">
|
||||
上次失败:{task.superdir_auto_last_error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="rounded-md border border-cyber-border-subtle bg-cyber-bg-tertiary/40 p-3 space-y-3">
|
||||
{/* 两类通知的性质完全不同,所以分成两个开关:
|
||||
异常低频且意味着任务已经停止工作 —— 默认开;
|
||||
|
||||
Reference in New Issue
Block a user