scheduler

package
v1.0.0-rc.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProbeModeAuto     = "auto"
	ProbeModeManual   = "manual"
	ProbeModeDisabled = "disabled"
)
View Source
const (
	PauseReasonPeerRatio = "做种竞争度过高"
)

Variables

BrushDiscountLevels 是刷流入场可选的优惠类型(与 site/v2 的 DiscountLevel 取值一致)。

View Source
var ErrAttendanceBusy = errors.New("站点正在探测或签到,请稍后再试")

ErrAttendanceBusy 表示该站正在被登录探测或另一次签到占用(共用单站单飞锁)。

View Source
var ErrBrushBusy = errors.New("刷流任务正在运行,请稍后再试")

ErrBrushBusy 表示这个任务正在运行(定时一轮与手动「立即运行」不会同时跑)。

View Source
var ErrBrushStopped = errors.New("刷流服务已停止")

ErrBrushStopped 表示刷流监控已经停止(进程正在退出)。

View Source
var ErrReseedBusy = errors.New("辅种正在运行,请等这一轮结束")

ErrReseedBusy 表示已经有一轮辅种在跑。

Functions

func ComputeTier added in v0.35.0

func ComputeTier(state *models.SiteLoginState, effective, now time.Time) string

ComputeTier maps DaysRemaining into one of the predefined tier strings. The tier defines both the reminder urgency and whether quiet hours can be overridden (only banned-imminent overrides).

func DailyReportRand

func DailyReportRand(n int64) int64

DailyReportRand 是生产环境分配偏移用的随机数。

func DaysRemaining added in v0.35.0

func DaysRemaining(state *models.SiteLoginState, effective, now time.Time) int

DaysRemaining returns how many full days remain until the site's configured ban threshold elapses since the effective last-active time. Negative values mean the threshold has already been crossed.

func EffectiveActiveSource

func EffectiveActiveSource(state *models.SiteLoginState, effective time.Time) string

EffectiveActiveSource 返回判定活跃时间取自哪一列:last_access、api_last_login、 cookie_last_login、last_login、last_visit;没有依据时为 none。

func EffectiveLastActive added in v0.35.0

func EffectiveLastActive(state *models.SiteLoginState, _ time.Time) time.Time

EffectiveLastActive returns the most recent confirmed activity timestamp for a site.

Per research: site cleanup.php scripts predominantly check `last_access` (NexusPHP) / `last_action` (Unit3D) / `LastAccess` (Gazelle) / `lastModifiedDate` (mTorrent) — NOT `last_login`. So the probe-derived value prefers last_access-class timestamps and treats last_login-class timestamps (ApiLastLoginAt, CookieLastLoginAt) as supplementary signals, used only when last_access is missing:

  1. state.LastAccessAt
  2. max(state.ApiLastLoginAt, state.CookieLastLoginAt)
  3. state.LastLoginAt (legacy v1 field)

最近一次探测为 OK 时只用上面的结果(站点的数据就是事实,探测本身也刷新了它); 否则探测数据可能已过时,再与浏览器扩展上报的 LastVisitAt 取较新者, 避免探测坏掉后用户正常用浏览器访问,剩余天数却照样下降。

Types

type AttendanceMonitor

type AttendanceMonitor struct {
	Rand func(n int64) int64
	// contains filtered or unexported fields
}

AttendanceMonitor 每分钟检查一次开启了自动签到的站点:每站每天在时间窗内随机取一个时刻签到, 失败按 10、30 分钟退避重试最多 2 次,当天成功或已签后不再请求。结果写 SiteAttendanceLog, 当天所有站点都有结果后合成一条通知,经 MonitorNotifier 按通道静默时段投递。

func NewAttendanceMonitor

func NewAttendanceMonitor(cfg AttendanceMonitorConfig) *AttendanceMonitor

NewAttendanceMonitor 构造签到监控,不启动;调用 Start 开始调度。

func (*AttendanceMonitor) RunOnce

func (m *AttendanceMonitor) RunOnce(ctx context.Context)

RunOnce 处理一轮:为当天还没有记录的站点安排时刻,签到已到时刻的站点,并在都有结果后写当天的汇总通知。

func (*AttendanceMonitor) SignAll

SignAll 对所有开启了自动签到、当天还没有结果的站点立即签到一次,返回这些站点当天的记录。

func (*AttendanceMonitor) SignNow

func (m *AttendanceMonitor) SignNow(ctx context.Context, siteName string) (*models.SiteAttendanceLog, error)

SignNow 立即签到一次(手动或 ChatOps),不要求站点开启了自动签到。 成功、今日已签或不支持时写入当天的最终结果;失败只记下错误,不占用自动重试的次数。

func (*AttendanceMonitor) Start

func (m *AttendanceMonitor) Start()

Start 启动调度循环;重复调用无效果。

func (*AttendanceMonitor) Stop

func (m *AttendanceMonitor) Stop()

Stop 停止调度循环并等它退出。

func (*AttendanceMonitor) Today

func (m *AttendanceMonitor) Today() string

Today 返回进程时区的当天日期(YYYY-MM-DD),签到记录按它分天。

type AttendanceMonitorConfig

type AttendanceMonitorConfig struct {
	DB     *gorm.DB
	Sites  AttendanceSites
	Window AttendanceWindowSource
	Locker ProbeLocker
	// Notifier 为空时不发当天的签到汇总。
	Notifier *MonitorNotifier
	Clock    sitelogin.Clock
	Logger   *zap.SugaredLogger
	Tick     time.Duration
	// Location 是计算日期与时间窗的时区,默认进程时区(time.Local)。
	Location *time.Location
	// Rand 返回 [0, n) 的随机数,用于在时间窗内取时刻;测试可以注入确定的值。
	Rand func(n int64) int64
}

AttendanceMonitorConfig 是 AttendanceMonitor 的依赖。

type AttendanceSites

type AttendanceSites interface {
	AttendanceSite(siteName string) (v2.AttendanceCapable, bool)
}

AttendanceSites 按站点名取能签到的站点实例;生产环境取 UserInfoService 里注册的共享实例,与搜索、探测共用限速器。

type AttendanceSitesFunc

type AttendanceSitesFunc func(siteName string) (v2.AttendanceCapable, bool)

AttendanceSitesFunc 把函数适配为 AttendanceSites。

func (AttendanceSitesFunc) AttendanceSite

func (f AttendanceSitesFunc) AttendanceSite(siteName string) (v2.AttendanceCapable, bool)

type AttendanceWindowSource

type AttendanceWindowSource interface {
	AttendanceWindow() (string, string, error)
}

AttendanceWindowSource 返回签到时间窗(HH:MM,进程时区),即 core.ConfigStore.AttendanceWindow。

type BrushDownloaders

type BrushDownloaders interface {
	BrushDownloader(id uint) (downloader.Downloader, string, error)
}

BrushDownloaders 按 ID 取下载器实例(列种子、删种)与它的名称。

type BrushDownloadersFunc

type BrushDownloadersFunc func(id uint) (downloader.Downloader, string, error)

BrushDownloadersFunc 把函数适配为 BrushDownloaders。

func (BrushDownloadersFunc) BrushDownloader

func (f BrushDownloadersFunc) BrushDownloader(id uint) (downloader.Downloader, string, error)

type BrushMonitor

type BrushMonitor struct {
	// contains filtered or unexported fields
}

BrushMonitor 按任务的间隔运行刷流:每一轮先给任务名下的种子采样、按删种规则删除,再从站点的免费列表里 按入场条件挑种子,在限额之内经 PushTorrentToDownloader 推送(磁盘与站点容量闸门不变)。 只处理带本任务标签、并且有 BrushTorrent 记录的种子。

func NewBrushMonitor

func NewBrushMonitor(cfg BrushMonitorConfig) *BrushMonitor

NewBrushMonitor 构造刷流监控,不启动;调用 Start 开始调度。

func (*BrushMonitor) RunOnce

func (m *BrushMonitor) RunOnce(ctx context.Context)

RunOnce 依次运行到期的已启用任务(距上一轮满了任务的间隔),并每小时清理一次过期采样。

func (*BrushMonitor) RunTask

func (m *BrushMonitor) RunTask(ctx context.Context, taskID uint) (BrushRunResult, error)

RunTask 立即运行一轮(定时调度与「立即运行」接口共用);同一任务正在运行时返回 ErrBrushBusy, 监控已停止时返回 ErrBrushStopped。关闭的任务也能手动运行:删种照常执行,加种只在任务开启时进行。

func (*BrushMonitor) Start

func (m *BrushMonitor) Start()

Start 启动调度循环;重复调用、Stop 之后再调用都无效果。

func (*BrushMonitor) Stop

func (m *BrushMonitor) Stop()

Stop 停止调度、取消正在跑的定时或手动的一轮,并等它们全部退出;之后的 RunTask 返回 ErrBrushStopped。

func (*BrushMonitor) WithTaskLock

func (m *BrushMonitor) WithTaskLock(taskID uint, fn func() error) error

WithTaskLock 在任务没有运行时执行 fn(期间定时与手动运行都会拿到 ErrBrushBusy);任务正在运行时返回 ErrBrushBusy。 删除与修改任务走这里:一轮运行用的是开始时读到的配置,改动不能落在一轮的中途。

type BrushMonitorConfig

type BrushMonitorConfig struct {
	DB          *gorm.DB
	Sites       BrushSites
	Downloaders BrushDownloaders
	Push        BrushPushFunc
	Clock       sitelogin.Clock
	Logger      *zap.SugaredLogger
	Tick        time.Duration
	// Location 是统计按天归档的时区,默认进程时区(time.Local)。
	Location *time.Location
}

BrushMonitorConfig 是 BrushMonitor 的依赖。

type BrushPushFunc

BrushPushFunc 是推送入口,默认 internal.PushTorrentToDownloader(磁盘预算与站点容量闸门都在里面)。

type BrushRunResult

type BrushRunResult struct {
	TaskID   uint     `json:"task_id"`
	Sampled  int      `json:"sampled"`
	Removed  int      `json:"removed"`
	Gone     int      `json:"gone"`
	Listed   int      `json:"listed"`
	Eligible int      `json:"eligible"`
	Added    int      `json:"added"`
	Skipped  []string `json:"skipped,omitempty"`
	Errors   []string `json:"errors,omitempty"`
	// Stopped 说明这一轮为什么没有继续加种(限额已满、推送被闸门拒绝等);为空表示列表里能加的都加了。
	Stopped string `json:"stopped,omitempty"`
}

BrushRunResult 是一轮运行的摘要,也是「立即运行」接口的返回值。

func (BrushRunResult) Summary

func (r BrushRunResult) Summary() string

Summary 是写进任务 last_result 的一句话。

type BrushSites

type BrushSites interface {
	BrushSite(siteName string) (v2.Site, bool)
}

BrushSites 按站点名取共享站点实例;生产环境取 UserInfoService 里注册的实例,与搜索、登录探测共用限速器。

type BrushSitesFunc

type BrushSitesFunc func(siteName string) (v2.Site, bool)

BrushSitesFunc 把函数适配为 BrushSites。

func (BrushSitesFunc) BrushSite

func (f BrushSitesFunc) BrushSite(siteName string) (v2.Site, bool)

type CleanupMonitor added in v0.14.0

type CleanupMonitor struct {
	// contains filtered or unexported fields
}

func NewCleanupMonitor added in v0.14.0

func NewCleanupMonitor(db *gorm.DB, downloaderMgr *downloader.DownloaderManager) *CleanupMonitor

func (*CleanupMonitor) RunManual added in v0.14.0

func (c *CleanupMonitor) RunManual() (int, error)

func (*CleanupMonitor) Start added in v0.14.0

func (c *CleanupMonitor) Start() error

func (*CleanupMonitor) Stop added in v0.14.0

func (c *CleanupMonitor) Stop()

type CookieCloudWorker

type CookieCloudWorker struct {
	// contains filtered or unexported fields
}

CookieCloudWorker 按设置的间隔从 CookieCloud 同步已启用站点的 Cookie。

func NewCookieCloudWorker

func NewCookieCloudWorker(cfg CookieCloudWorkerConfig) *CookieCloudWorker

NewCookieCloudWorker 构造后台,不启动。

func (*CookieCloudWorker) Service

func (w *CookieCloudWorker) Service() *cookiecloud.Service

Service 返回 CookieCloud 服务。

func (*CookieCloudWorker) Start

func (w *CookieCloudWorker) Start()

Start 启动定时循环;重复调用无效果。

func (*CookieCloudWorker) Stop

func (w *CookieCloudWorker) Stop()

Stop 停止循环并等正在进行的同步退出。停止后不能再启动。

type CookieCloudWorkerConfig

type CookieCloudWorkerConfig struct {
	Service *cookiecloud.Service
	Clock   sitelogin.Clock
	Logger  *zap.SugaredLogger
	Tick    time.Duration
	// StartupDelay 是启动后第一次检查前的等待(默认 2 分钟)。
	StartupDelay time.Duration
}

CookieCloudWorkerConfig 是 CookieCloud 定时同步的依赖。

type CredentialDecryptor added in v0.35.0

type CredentialDecryptor interface {
	Decrypt(setting models.SiteSetting) (cookie string, err error)
}

CredentialDecryptor returns a usable cookie/api-key for a site. Real implementations decrypt SiteSetting.CookieEncrypted via core.ConfigStore; tests inject deterministic values.

type CronExpr added in v0.35.0

type CronExpr struct {
	// contains filtered or unexported fields
}

CronExpr is a tiny 5-field cron evaluator (minute hour dom month dow) covering the patterns used by LoginReminderMonitor:

  • Numeric value: "10", "22"
  • Comma list: "10,22"
  • Wildcard: "*"
  • Step: "*/5", "*/15"
  • Range: "1-5"

Day-of-week uses 0-6 with 0=Sunday (the standard cron convention). This is intentionally NOT a full cron implementation — it is purpose-built for reminder schedules and rejects unsupported syntax with a parse error so misconfigurations fail loud at config time, not silently at midnight.

func ParseCron added in v0.35.0

func ParseCron(spec string) (*CronExpr, error)

ParseCron parses a 5-field cron expression like "0 10,22 * * *".

func (*CronExpr) Match added in v0.35.0

func (c *CronExpr) Match(t time.Time) bool

Match reports whether the given time falls exactly on a cron tick (minute granularity). It does NOT consider seconds.

func (*CronExpr) WindowStart added in v0.35.0

func (c *CronExpr) WindowStart(t time.Time) time.Time

WindowStart returns the most recent cron tick at or before t. The boundary is used by reminder dedup: two events that map to the same WindowStart are considered the same window and at most one reminder fires per window.

type DailyReportJob

type DailyReportJob struct {
	// contains filtered or unexported fields
}

DailyReportJob 每分钟检查一次:到了设定时刻加本安装固定的偏移后,若当天还没发,就读当天的快照算出增量, 连同登录状态异常的站点与签到结果写成一条战报,经 MonitorNotifier 按通道写日志行(同一天每个通道只一行, 重启也不重发),由投递器发送并按通道静默时段顺延。每天还顺带清理一次 400 天以前的快照。

func NewDailyReportJob

func NewDailyReportJob(cfg DailyReportJobConfig) *DailyReportJob

NewDailyReportJob 构造战报任务,不启动;调用 Start 开始调度。

func (*DailyReportJob) RunOnce

func (j *DailyReportJob) RunOnce(ctx context.Context)

RunOnce 处理一轮:每天清理一次旧快照;到了发送时刻且当天还没发就写战报。

func (*DailyReportJob) Start

func (j *DailyReportJob) Start()

Start 启动调度循环;重复调用无效果。

func (*DailyReportJob) Stop

func (j *DailyReportJob) Stop()

Stop 停止调度循环并等它退出。

type DailyReportJobConfig

type DailyReportJobConfig struct {
	DB *gorm.DB
	// Settings 返回战报配置:是否开启、发送时刻(HH:MM,Location 时区)与接收通道(core.ConfigStore.DailyReportSettings)。
	Settings func() (enabled bool, hhmm string, channelIDs []uint, err error)
	// Offset 返回本安装固定的发送偏移(core.ConfigStore.DailyReportOffset)。
	Offset func() (time.Duration, error)
	// EnabledSites 返回已启用站点名(小写)。战报只算这些站点:已禁用站点的增量、残留的登录状态与签到结果都不出现。
	// 为空时不过滤;返回错误时这一轮不发。
	EnabledSites func() (map[string]bool, error)
	// History 为空(用户数据仓库没起来)时不发战报,也不清理快照。
	History v2.UserInfoHistoryRepo
	// Notifier 为空时不发。
	Notifier *MonitorNotifier
	Clock    sitelogin.Clock
	Logger   *zap.SugaredLogger
	Tick     time.Duration
	// Location 是计算日期与发送时刻的时区,默认进程时区;须与 History 的时区一致。
	Location *time.Location
}

DailyReportJobConfig 是 DailyReportJob 的依赖。

type DeadTorrentDownloader

type DeadTorrentDownloader struct {
	Name string
	DL   downloader.Downloader
}

DeadTorrentDownloader 是一台要扫描的下载器。

type DeadTorrentMonitor

type DeadTorrentMonitor struct {
	// contains filtered or unexported fields
}

DeadTorrentMonitor 按设置的间隔扫描各下载器里 tracker 报告未注册或不存在的种子,只发通知,不删种。 同一批失效种子只通知一次;新出现失效种子时再通知(列出全部)。

func NewDeadTorrentMonitor

func NewDeadTorrentMonitor(cfg DeadTorrentMonitorConfig) *DeadTorrentMonitor

NewDeadTorrentMonitor 构造监控,不启动。

func (*DeadTorrentMonitor) RunOnce

func (m *DeadTorrentMonitor) RunOnce(ctx context.Context) int

RunOnce 在开启且到了间隔时扫描一轮;返回这一轮通知了几台下载器。

func (*DeadTorrentMonitor) Start

func (m *DeadTorrentMonitor) Start()

Start 启动调度循环;重复调用无效果。

func (*DeadTorrentMonitor) Stop

func (m *DeadTorrentMonitor) Stop()

Stop 停止调度循环并等它退出(包括正在跑的一轮)。

type DeadTorrentMonitorConfig

type DeadTorrentMonitorConfig struct {
	// Settings 返回是否开启、扫描间隔与接收通知的通道。
	Settings func() (enabled bool, interval time.Duration, channelIDs []uint, err error)
	// Downloaders 返回已启用、能连上的下载器;连不上的放在 errs 里(只记日志)。
	Downloaders func(ctx context.Context) (dls []DeadTorrentDownloader, errs []error)
	Notifier    *MonitorNotifier
	// Resolver 按 tracker 识别站点;为空时用全部内置站点。
	Resolver func() *v2.TrackerResolver
	Clock    sitelogin.Clock
	Logger   *zap.SugaredLogger
	Tick     time.Duration
}

DeadTorrentMonitorConfig 是失效种子定时扫描的依赖。

type FallbackProvider

type FallbackProvider interface {
	FallbackFor(ctx context.Context, setting models.SiteSetting, def *v2.SiteDefinition) sitelogin.Transport
}

FallbackProvider 返回本次探测可用的后备通道(CloakBrowser)。每次探测前调用一次,实现方每次从库里读配置, 改配置不需要重启;配置不全、架构不支持、缺 Cookie 或缺身份信息时返回 nil,探测只用主通道。 只有主通道被拦截、网络错误或限流时才会真正用到它(见 sitelogin.ProbeWithFallback)。

type FreeEndMonitor added in v0.3.0

type FreeEndMonitor struct {
	// contains filtered or unexported fields
}

func NewFreeEndMonitor added in v0.3.0

func NewFreeEndMonitor(db *gorm.DB, downloaderMgr *downloader.DownloaderManager) *FreeEndMonitor

func (*FreeEndMonitor) CancelTorrent added in v0.3.0

func (m *FreeEndMonitor) CancelTorrent(torrentID uint)

func (*FreeEndMonitor) ScheduleTorrent added in v0.3.0

func (m *FreeEndMonitor) ScheduleTorrent(torrent models.TorrentInfo)

func (*FreeEndMonitor) Start added in v0.3.0

func (m *FreeEndMonitor) Start() error

func (*FreeEndMonitor) Stop added in v0.3.0

func (m *FreeEndMonitor) Stop()

func (*FreeEndMonitor) TestHandleFreeEndedTorrent added in v0.3.0

func (m *FreeEndMonitor) TestHandleFreeEndedTorrent(torrent models.TorrentInfo)

TestHandleFreeEndedTorrent 暴露给测试/调试命令使用

type JobStatus added in v0.31.0

type JobStatus struct {
	SiteName  string
	RSSName   string
	Running   bool
	StartedAt time.Time
}

type LoginReminderConfig added in v0.35.0

type LoginReminderConfig struct {
	DB *gorm.DB
	// Notifier 为空时只记录提醒决策,不投递(没有可用的通知服务)。
	Notifier *MonitorNotifier
	// UserInfo 非空时探测经 UserInfoService.FetchAndSave 进行:用与搜索共用的站点实例和限速器,
	// 成功时顺带刷新用户统计,也不再调用 Resolver。为空(仓库初始化失败)时退回 Resolver 新建实例。
	UserInfo sitelogin.UserInfoFetcher
	// Fallback 为空时不用后备通道。
	Fallback     FallbackProvider
	Resolver     SiteResolver
	Decryptor    CredentialDecryptor
	Clock        sitelogin.Clock
	Logger       *zap.SugaredLogger
	ProbeEvery   time.Duration
	ProbeTick    time.Duration
	ReminderTick time.Duration
	// DefinitionLookup 判断站点是否有内置定义,默认查 v2.GetDefinitionRegistry()。
	DefinitionLookup func(siteName string) (*v2.SiteDefinition, bool)
}

LoginReminderConfig holds the dependencies needed to construct a LoginReminderMonitor.

type LoginReminderMonitor added in v0.35.0

type LoginReminderMonitor struct {
	// contains filtered or unexported fields
}

LoginReminderMonitor runs two cooperating loops:

  1. probe loop(每分钟检查一次):逐个探测到期的 auto 模式站点。到期条件是 NextProbeAt 已到,或 ProbeRequestedAt 晚于 LastProbeStartedAt。下一次探测 时间按结果退避(见 nextProbeDelay),首轮按每站固定抖动分散,重启不补探。

  2. reminder loop(每分钟):计算封号提醒等级,并判断探测失败与恢复提醒。 所有通知只写 MonitorNotificationLog,由 MonitorNotifier 按通道处理静默时段、 经 live 通道发送并重试;监控自己不创建通道实例。

SiteLoginState 的每一列只有一个写者,全部按列 Updates,不整行 Save:

探测(持有单站锁):last_probe_at、last_probe_started_at、last_probe_status、
  last_probe_error、consecutive_probe_failures、first_failure_at、last_success_at、
  next_probe_at、probe_jitter_seconds、last_access_at、last_login_at、
  api_last_login_at、cookie_last_login_at、last_consistency_check、access_stale_since
提醒循环:last_reminder_tier、last_reminder_sent_at、last_failure_notified_at
配置接口:ban_threshold_days、remind_before_days、reminder_cron、
  notification_channel_ids、probe_mode
访问上报:last_visit_at
探测请求(RequestProbe):probe_requested_at

The monitor never issues raw HTTP itself; all site I/O passes through the site/v2 driver layer (which inherits the project's circuit breaker and rate limiter).

func NewLoginReminderMonitor added in v0.35.0

func NewLoginReminderMonitor(cfg LoginReminderConfig) *LoginReminderMonitor

NewLoginReminderMonitor builds a LoginReminderMonitor. It does not start the loops; call Start to begin processing.

func (*LoginReminderMonitor) Notifier

func (m *LoginReminderMonitor) Notifier() *MonitorNotifier

Notifier 返回监控使用的通知投递器(可能为 nil)。

func (*LoginReminderMonitor) RequestProbe

func (m *LoginReminderMonitor) RequestProbe(siteName string) error

RequestProbe 记录一次探测请求:auto 模式下探测循环会在一分钟内探测该站,不在调用方的请求里同步探测。 用监控自己的时钟写 probe_requested_at,与 last_probe_started_at 可比。凭证与站点配置入口 按「写库 → 刷新站点注册 → RequestProbe」调用,所以请求早于某次探测开始时,那次探测一定读到新配置; 晚于开始时,该站在那次探测之后仍然到期。

func (*LoginReminderMonitor) RunDueProbes

func (m *LoginReminderMonitor) RunDueProbes(ctx context.Context)

RunDueProbes 逐个探测到期的 auto 模式站点。NextProbeAt 为空(升级后的老数据、新建的行) 时只安排首轮时间「当前时间 + 固定抖动」,不立即探测,除非有人请求过探测。

func (*LoginReminderMonitor) RunProbeOnce added in v0.35.0

func (m *LoginReminderMonitor) RunProbeOnce(ctx context.Context)

RunProbeOnce probes every enabled site whose mode allows cron probing, regardless of NextProbeAt. Exported so tests can drive the probe phase directly with a fake clock. Sites whose probe slot is held by another trigger source are skipped — R23 shared single-flight.

func (*LoginReminderMonitor) RunProbeOnceForSite added in v0.35.0

func (m *LoginReminderMonitor) RunProbeOnceForSite(ctx context.Context, siteName string) bool

RunProbeOnceForSite probes a single site by name. Used for manual endpoint triggering (manualTrigger=true), bypassing mode restrictions. Acquires the shared probe lock; returns false if another caller already holds it.

func (*LoginReminderMonitor) RunProbeOnceForSiteLocked added in v0.35.0

func (m *LoginReminderMonitor) RunProbeOnceForSiteLocked(ctx context.Context, siteName string)

RunProbeOnceForSiteLocked runs the probe assuming the caller already holds the per-site probe lock (via TryAcquireProbeLock). The web handler uses this split so the HTTP layer can shape its 409 response from TryAcquireProbeLock before dispatching the actual probe work.

func (*LoginReminderMonitor) RunReminderOnce added in v0.35.0

func (m *LoginReminderMonitor) RunReminderOnce(ctx context.Context)

RunReminderOnce iterates enabled sites, computes each site's tier, fires reminders that are due, and decides probe failure / recovery notices. Exported for testability.

func (*LoginReminderMonitor) SendTestReminder added in v0.35.0

func (m *LoginReminderMonitor) SendTestReminder(ctx context.Context, siteName string) error

SendTestReminder immediately sends a test login-reminder notification for one site.

func (*LoginReminderMonitor) Start added in v0.35.0

func (m *LoginReminderMonitor) Start()

Start launches the probe and reminder loops and the notification delivery loop. Calling Start twice is a no-op.

func (*LoginReminderMonitor) Stop added in v0.35.0

func (m *LoginReminderMonitor) Stop()

Stop signals the loops to exit and waits for them to drain.

func (*LoginReminderMonitor) TryAcquireProbeLock added in v0.35.0

func (m *LoginReminderMonitor) TryAcquireProbeLock(siteName string) (release func(), ok bool)

TryAcquireProbeLock attempts to acquire the per-site probe mutex without blocking. Returns (release, true) on success — caller MUST invoke release() in defer to free the slot. Returns (nil, false) if another caller (cron, REST, or extension) already holds the mutex; the caller should surface a 409-style "probe in progress" response. R23: this single map is the shared single-flight registry across all probe trigger sources.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) BrushDownloader

func (m *Manager) BrushDownloader(id uint) (downloader.Downloader, string, error)

BrushDownloader 按下载器 ID 取管理器里的实例(刷流列种子、删种用);下载器不存在或未启用时返回错误。

func (*Manager) GetAttendanceMonitor

func (m *Manager) GetAttendanceMonitor() *AttendanceMonitor

GetAttendanceMonitor 返回每日签到监控,没有接线时为 nil。

func (*Manager) GetBrushMonitor

func (m *Manager) GetBrushMonitor() *BrushMonitor

GetBrushMonitor 返回刷流监控,没有接线时为 nil。

func (*Manager) GetCookieCloudWorker

func (m *Manager) GetCookieCloudWorker() *CookieCloudWorker

GetCookieCloudWorker 返回 CookieCloud 定时同步(未接线时为 nil)。

func (*Manager) GetDeadTorrentMonitor

func (m *Manager) GetDeadTorrentMonitor() *DeadTorrentMonitor

GetDeadTorrentMonitor 返回失效种子定时扫描(未接线时为 nil)。

func (*Manager) GetDownloaderManager added in v0.2.0

func (m *Manager) GetDownloaderManager() *downloader.DownloaderManager

GetDownloaderManager 获取下载器管理器

func (*Manager) GetFreeEndMonitor added in v0.3.0

func (m *Manager) GetFreeEndMonitor() *FreeEndMonitor

GetFreeEndMonitor 获取免费结束监控器

func (*Manager) GetLoginReminderMonitor added in v0.35.0

func (m *Manager) GetLoginReminderMonitor() *LoginReminderMonitor

GetLoginReminderMonitor returns the registered monitor, or nil if not yet wired. Used by web handlers that want to trigger ad-hoc probes.

func (*Manager) GetReseedWorker

func (m *Manager) GetReseedWorker() *ReseedWorker

GetReseedWorker 返回辅种后台(未接线时为 nil)。

func (*Manager) GetTransferWorker

func (m *Manager) GetTransferWorker() *TransferWorker

GetTransferWorker 返回转移做种后台(未接线时为 nil)。

func (*Manager) InitFreeEndMonitor added in v0.3.0

func (m *Manager) InitFreeEndMonitor()

func (*Manager) LastVersion

func (m *Manager) LastVersion() int64

func (*Manager) ListJobs added in v0.31.0

func (m *Manager) ListJobs() []JobStatus

func (*Manager) Reload

func (m *Manager) Reload(cfg *models.Config)

func (*Manager) SetAttendanceMonitor

func (m *Manager) SetAttendanceMonitor(mon *AttendanceMonitor)

SetAttendanceMonitor 登记每日签到监控;替换旧实例时先停掉旧的。

func (*Manager) SetBrushMonitor

func (m *Manager) SetBrushMonitor(mon *BrushMonitor)

SetBrushMonitor 登记刷流监控;替换旧实例时先停掉旧的。

func (*Manager) SetCookieCloudWorker

func (m *Manager) SetCookieCloudWorker(w *CookieCloudWorker)

SetCookieCloudWorker 登记 CookieCloud 定时同步;替换旧实例时先停掉旧的(在锁外停,理由见 StopAll)。

func (*Manager) SetDailyReportJob

func (m *Manager) SetDailyReportJob(job *DailyReportJob)

SetDailyReportJob 登记每日战报任务;替换旧实例时先停掉旧的。

func (*Manager) SetDeadTorrentMonitor

func (m *Manager) SetDeadTorrentMonitor(mon *DeadTorrentMonitor)

SetDeadTorrentMonitor 登记失效种子定时扫描;替换旧实例时先停掉旧的。

func (*Manager) SetLoginReminderMonitor added in v0.35.0

func (m *Manager) SetLoginReminderMonitor(mon *LoginReminderMonitor)

SetLoginReminderMonitor wires a fully-constructed LoginReminderMonitor into the manager. It is intended to be called by the web layer after the monitor has been built with a SiteResolver that knows how to produce v2.Site instances. Calling this twice replaces and stops the previous instance. Pass nil to detach without stopping.

func (*Manager) SetReseedWorker

func (m *Manager) SetReseedWorker(w *ReseedWorker)

SetReseedWorker 登记辅种后台;替换旧实例时先停掉旧的。

func (*Manager) SetTransferWorker

func (m *Manager) SetTransferWorker(w *TransferWorker)

SetTransferWorker 登记转移做种后台;替换旧实例时先停掉旧的。

func (*Manager) Start

func (m *Manager) Start(site models.SiteGroup, r models.RSSConfig, runner func(ctx context.Context))

func (*Manager) StartAll

func (m *Manager) StartAll(cfg *models.Config)

StartAll 按配置启动所有任务(不做停止),并记下用户要求运行任务。

func (*Manager) Stop

func (m *Manager) Stop(site models.SiteGroup, rssName string)

func (*Manager) StopAll

func (m *Manager) StopAll()

StopAll 是进程退出前的最终关闭:取消所有任务并等待结束,停掉全部监控器和配置事件订阅。 之后不能再用 StartAll 恢复;调度器里的「停止所有任务」用 StopJobs。

func (*Manager) StopJobs

func (m *Manager) StopJobs()

StopJobs 停止全部 RSS 任务(调度器里的「停止所有任务」)。免费到期、自动删种、竞争度、 登录提醒和签到监控继续运行,配置热重载也照常;之后的配置变更不会把任务重新拉起,直到 StartAll。

func (*Manager) TransferDownloader

func (m *Manager) TransferDownloader(ctx context.Context, id uint) (downloader.Downloader, models.DownloaderSetting, error)

TransferDownloader 按下载器 ID 取管理器里的实例与配置(转移做种用);下载器不存在、未启用或连不上时返回错误。

type MonitorNotifier

type MonitorNotifier struct {
	// contains filtered or unexported fields
}

MonitorNotifier 负责后台监控通知的入队与投递,是这些通知唯一的重试者。

func NewMonitorNotifier

func NewMonitorNotifier(db *gorm.DB, sender MonitorSender, clock sitelogin.Clock, logger *zap.SugaredLogger) *MonitorNotifier

NewMonitorNotifier 构造投递器。sender 为 nil 时不写日志行(没有可用的通知服务)。

func (*MonitorNotifier) DeliverDue

func (n *MonitorNotifier) DeliverDue(ctx context.Context) int

DeliverDue 投递所有到期的 pending 行,返回成功发送的条数。

func (*MonitorNotifier) DeliverNow

func (n *MonitorNotifier) DeliverNow(ctx context.Context, e MonitorNotifyEntry) error

DeliverNow 立即投递某个决策的全部 pending 行(测试提醒用),返回首个失败的错误。

func (*MonitorNotifier) Enabled

func (n *MonitorNotifier) Enabled() bool

Enabled 报告投递器是否可用(有数据库也有发送方)。

func (*MonitorNotifier) Enqueue

Enqueue 按目标通道各写一行。通道此刻处于自己的静默时段时,该行顺延到静默结束。 返回新写入的行数;已存在的行(同一决策重做)不计入。

func (*MonitorNotifier) Logged

func (n *MonitorNotifier) Logged(ctx context.Context, source, subject, kind, eventKey string) bool

Logged 报告同一决策(Source、Subject、Kind、EventKey)是否已经写过投递行,任何通道都算。

func (*MonitorNotifier) Start

func (n *MonitorNotifier) Start()

Start 启动每分钟一次的投递循环;重复调用无副作用。

func (*MonitorNotifier) Stop

func (n *MonitorNotifier) Stop()

Stop 停止投递循环并等待当前一轮结束。

type MonitorNotifyEntry

type MonitorNotifyEntry struct {
	Source   string
	Subject  string
	Kind     string
	EventKey string
	Title    string
	Text     string
	// ConfIDs 为空时发给决策当时所有启用的通道。
	ConfIDs []uint
	// BypassQuiet 为 true 时不受通道静默时段限制(封号前最后一天、测试提醒)。
	BypassQuiet bool
}

MonitorNotifyEntry 是一次「决定发送」。同一个 (Source, Subject, Kind, EventKey) 重复写入不会重复发送。

type MonitorSender

type MonitorSender interface {
	Send(ctx context.Context, confID uint, title, text string) error
}

MonitorSender 经 live 通道同步发送一条通知到指定通道,失败或超时直接返回错误,不写 outbox。

生产实现包装 app.NotificationService.PushSync(scheduler 不能依赖 internal/app,后者依赖 scheduler)。 不能换成 Push:Push 在 live 发送失败后转写 outbox 并返回 nil,而 outbox 用 registry.Make 新建通道实例, 发不了 QQ / Telegram 这类有状态通道,日志行也会被误记为已送达。

type MonitorSenderFunc

type MonitorSenderFunc func(ctx context.Context, confID uint, title, text string) error

MonitorSenderFunc 让普通函数实现 MonitorSender。

func (MonitorSenderFunc) Send

func (f MonitorSenderFunc) Send(ctx context.Context, confID uint, title, text string) error

type PeerRatioMonitor added in v0.23.0

type PeerRatioMonitor struct {
	// contains filtered or unexported fields
}

func NewPeerRatioMonitor added in v0.23.0

func NewPeerRatioMonitor(db *gorm.DB, downloaderMgr *downloader.DownloaderManager) *PeerRatioMonitor

func (*PeerRatioMonitor) Start added in v0.23.0

func (p *PeerRatioMonitor) Start() error

func (*PeerRatioMonitor) Stop added in v0.23.0

func (p *PeerRatioMonitor) Stop()

type ProbeLocker

type ProbeLocker interface {
	TryAcquireProbeLock(siteName string) (release func(), ok bool)
}

ProbeLocker 是登录探测与签到共用的单站单飞锁,即 LoginReminderMonitor.TryAcquireProbeLock。

type ReseedWorker

type ReseedWorker struct {
	// contains filtered or unexported fields
}

ReseedWorker 按设置的间隔运行辅种;「立即运行」在后台跑一轮,同一时间只有一轮。

func NewReseedWorker

func NewReseedWorker(cfg ReseedWorkerConfig) *ReseedWorker

NewReseedWorker 构造后台,不启动。

func (*ReseedWorker) RunNow

func (w *ReseedWorker) RunNow() error

RunNow 在后台马上跑一轮(不等它结束);已经有一轮在跑时返回 ErrReseedBusy。

func (*ReseedWorker) Running

func (w *ReseedWorker) Running() bool

Running 报告是不是有一轮在跑。

func (*ReseedWorker) Service

func (w *ReseedWorker) Service() *reseed.Service

Service 返回辅种服务。

func (*ReseedWorker) Start

func (w *ReseedWorker) Start()

Start 启动定时循环;重复调用无效果。

func (*ReseedWorker) Stop

func (w *ReseedWorker) Stop()

Stop 停止循环并等正在跑的一轮(包括「立即运行」)退出。停止后不能再启动。

type ReseedWorkerConfig

type ReseedWorkerConfig struct {
	Service *reseed.Service
	// Transfer 在建了新的辅种任务后唤醒,让任务马上开始加入与校验
	Transfer *TransferWorker
	Clock    sitelogin.Clock
	Logger   *zap.SugaredLogger
	Tick     time.Duration
	// StartupDelay 是启动后第一次检查前的等待(默认 3 分钟)。
	StartupDelay time.Duration
}

ReseedWorkerConfig 是辅种后台的依赖。

type SiteResolver added in v0.35.0

type SiteResolver interface {
	Resolve(setting models.SiteSetting) (*v2.SiteDefinition, v2.Site, error)
}

SiteResolver wires a SiteSetting row into a v2.Site instance plus its SiteDefinition. It is injected so that tests can substitute fake sites without touching the global site registry or HTTP layer.

type TransferRuleRun

type TransferRuleRun struct {
	Result   transfer.RuleResult `json:"result"`
	Summary  string              `json:"summary"`
	RunError string              `json:"error,omitempty"`
}

TransferRuleRun 是「立即运行」一条规则的结果;RunError 不为空表示这一轮没跑完(下载器不可用等)。

type TransferWorker

type TransferWorker struct {
	// contains filtered or unexported fields
}

TransferWorker 定时推进转移做种任务,并运行到期的定时规则。建了新任务后可以 Trigger 立即跑一轮。

func NewTransferWorker

func NewTransferWorker(cfg TransferWorkerConfig) *TransferWorker

NewTransferWorker 构造后台,不启动。

func (*TransferWorker) RunOnce

func (w *TransferWorker) RunOnce(ctx context.Context) (stepped, created int)

RunOnce 推进全部未结束的任务一步,再跑到期的定时规则;返回状态有变化的任务数与新建的任务数。

func (*TransferWorker) RunRuleNow

func (w *TransferWorker) RunRuleNow(ctx context.Context, id uint) (TransferRuleRun, error)

RunRuleNow 立即运行一条规则并记下结果;与后台的定时运行轮流进行,不会同时挑种子。

func (*TransferWorker) Service

func (w *TransferWorker) Service() *transfer.Service

Service 返回转移做种服务。

func (*TransferWorker) Start

func (w *TransferWorker) Start()

Start 启动循环;重复调用无效果。

func (*TransferWorker) Stop

func (w *TransferWorker) Stop()

Stop 停止循环并等正在跑的一轮结束。

func (*TransferWorker) Trigger

func (w *TransferWorker) Trigger()

Trigger 让循环马上跑一轮(不等下一个间隔);不阻塞。

type TransferWorkerConfig

type TransferWorkerConfig struct {
	Service *transfer.Service
	DB      *gorm.DB
	Clock   sitelogin.Clock
	Logger  *zap.SugaredLogger
	Tick    time.Duration
}

TransferWorkerConfig 是转移做种后台的依赖。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL