Documentation
¶
Index ¶
- Constants
- func AddErrorLogItem(e ErrorLogItem) error
- func AddLogItem(l LogItem) error
- func AddLogItems(ls []LogItem) error
- func AddSchedule(item Schedule) error
- func AddTask(item Task) error
- func DeleteTokenById(id bson.ObjectId) error
- func GetActionListTotal(filter interface{}) (int, error)
- func GetChallengeListTotal(filter interface{}) (int, error)
- func GetConfigSpiderData(spider Spider) (entity.ConfigSpiderData, error)
- func GetExecutables() (executables []entity.Executable, err error)
- func GetLocalLog(logPath string) (fileBytes []byte, err error)
- func GetLocalSystemInfo() (sysInfo entity.SystemInfo, err error)
- func GetLogItemTotal(query bson.M, keyword string) (int, error)
- func GetNodeCount(query interface{}) (int, error)
- func GetPathValues() (paths []string)
- func GetProjectCount(filter interface{}) (int, error)
- func GetProjectListTotal(filter interface{}) (int, error)
- func GetRawSetting(keyword string, pointer interface{}) error
- func GetScheduleCount(filter interface{}) (int, error)
- func GetSpiderCount(filter interface{}) (int, error)
- func GetSystemEnv(key string) string
- func GetTaskCount(query interface{}) (int, error)
- func GetTaskListTotal(filter interface{}) (int, error)
- func GetUserListTotal(filter interface{}) (int, error)
- func GetVisitDays(uid bson.ObjectId) (int, error)
- func IsMaster() bool
- func RemoveAction(id bson.ObjectId) error
- func RemoveAllSpider() error
- func RemoveFile(path string) error
- func RemoveProject(id bson.ObjectId) error
- func RemoveSchedule(id bson.ObjectId) error
- func RemoveSpider(id bson.ObjectId) error
- func RemoveTask(id string) error
- func RemoveTaskBySpiderId(id bson.ObjectId) error
- func RemoveTaskByStatus(status string) error
- func RemoveUser(id bson.ObjectId) error
- func ResetNodeStatusToOffline(list []string)
- func UpdateAction(id bson.ObjectId, item Action) error
- func UpdateErrorLogCount(id string) (err error)
- func UpdateMasterNodeInfo(key string, ip string, mac string, hostname string) error
- func UpdateNode(id bson.ObjectId, item Node) error
- func UpdateProject(id bson.ObjectId, item Project) error
- func UpdateSchedule(id bson.ObjectId, item Schedule) error
- func UpdateSpider(id bson.ObjectId, item Spider) error
- func UpdateTaskErrorLogs(taskId string, errorRegexPattern string) error
- func UpdateTaskResultCount(id string) (err error)
- func UpdateTaskToAbnormal(nodeId bson.ObjectId) error
- func UpdateUser(id bson.ObjectId, item User) error
- type Action
- type Base
- type Challenge
- func GetChallenge(id bson.ObjectId) (Challenge, error)
- func GetChallengeByName(name string) (Challenge, error)
- func GetChallengeList(filter interface{}, skip int, limit int, sortKey string) ([]Challenge, error)
- func GetChallengeListWithAchieved(filter interface{}, skip int, limit int, sortKey string, uid bson.ObjectId) ([]Challenge, error)
- type ChallengeAchievement
- type DocumentMeta
- type Env
- type ErrorLogItem
- type File
- type GridFs
- type LogItem
- type Node
- type Project
- type Schedule
- type SecuritySetting
- type Setting
- type Spider
- func GetSpider(id bson.ObjectId) (Spider, error)
- func GetSpiderAllList(filter interface{}) (spiders []Spider, err error)
- func GetSpiderByFileId(fileId bson.ObjectId) *Spider
- func GetSpiderByName(name string) Spider
- func GetSpiderList(filter interface{}, skip int, limit int, sortStr string) ([]Spider, int, error)
- type Task
- func (t *Task) Delete() error
- func (t *Task) GetErrorLogItems(n int) (errLogItems []ErrorLogItem, err error)
- func (t *Task) GetLogItems(keyword string, page int, pageSize int) (logItems []LogItem, logTotal int, err error)
- func (t *Task) GetNode() (Node, error)
- func (t *Task) GetResults(pageNum int, pageSize int) (results []interface{}, total int, err error)
- func (t *Task) GetSpider() (Spider, error)
- func (t *Task) Save() error
- type TaskDailyItem
- type Token
- type User
- type UserSetting
- type Variable
Constants ¶
View Source
const (
Yes = "Y"
)
Variables ¶
This section is empty.
Functions ¶
func AddErrorLogItem ¶
func AddErrorLogItem(e ErrorLogItem) error
func AddLogItem ¶
func AddLogItems ¶
func AddSchedule ¶
func DeleteTokenById ¶
func GetActionListTotal ¶
func GetChallengeListTotal ¶
func GetConfigSpiderData ¶
func GetConfigSpiderData(spider Spider) (entity.ConfigSpiderData, error)
获取爬虫定时任务
func GetExecutables ¶
func GetExecutables() (executables []entity.Executable, err error)
func GetLocalSystemInfo ¶
func GetLocalSystemInfo() (sysInfo entity.SystemInfo, err error)
func GetPathValues ¶
func GetPathValues() (paths []string)
func GetProjectCount ¶
func GetProjectListTotal ¶
func GetRawSetting ¶
func GetScheduleCount ¶
func GetSystemEnv ¶
func GetTaskListTotal ¶
func GetUserListTotal ¶
func RemoveAction ¶
func RemoveFile ¶
func RemoveProject ¶
func RemoveSchedule ¶
func RemoveTask ¶
func RemoveTaskByStatus ¶
func RemoveUser ¶
func ResetNodeStatusToOffline ¶
func ResetNodeStatusToOffline(list []string)
根据redis的key值,重置node节点为offline
func UpdateMasterNodeInfo ¶
func UpdateTaskErrorLogs ¶
update task error logs
func UpdateTaskToAbnormal ¶
convert all running tasks to abnormal tasks
Types ¶
type Action ¶
type Action struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
Type string `json:"type" bson:"type"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetActionList ¶
type Challenge ¶
type Challenge struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
Name string `json:"name" bson:"name"`
TitleCn string `json:"title_cn" bson:"title_cn"`
TitleEn string `json:"title_en" bson:"title_en"`
DescriptionCn string `json:"description_cn" bson:"description_cn"`
DescriptionEn string `json:"description_en" bson:"description_en"`
Difficulty int `json:"difficulty" bson:"difficulty"`
Path string `json:"path" bson:"path"`
// 前端展示
Achieved bool `json:"achieved" bson:"achieved"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetChallengeByName ¶
func GetChallengeList ¶
type ChallengeAchievement ¶
type ChallengeAchievement struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
ChallengeId bson.ObjectId `json:"challenge_id" bson:"challenge_id"`
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetChallengeAchievementList ¶
func GetChallengeAchievementList(filter interface{}, skip int, limit int, sortKey string) ([]ChallengeAchievement, error)
func (*ChallengeAchievement) Add ¶
func (ca *ChallengeAchievement) Add() error
func (*ChallengeAchievement) Save ¶
func (ca *ChallengeAchievement) Save() error
type DocumentMeta ¶
type ErrorLogItem ¶
type ErrorLogItem struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
TaskId string `json:"task_id" bson:"task_id"`
Message string `json:"msg" bson:"msg"`
LogId bson.ObjectId `json:"log_id" bson:"log_id"`
Seq int64 `json:"seq" bson:"seq"`
Ts time.Time `json:"ts" bson:"ts"`
ExpireTs time.Time `json:"expire_ts" bson:"expire_ts"`
}
type GridFs ¶
type GridFs struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
ChunkSize int32 `json:"chunk_size" bson:"chunkSize"`
UploadDate time.Time `json:"upload_date" bson:"uploadDate"`
Length int32 `json:"length" bson:"length"`
Md5 string `json:"md_5" bson:"md5"`
Filename string `json:"filename" bson:"filename"`
}
func GetAllGridFs ¶
func GetAllGridFs() []*GridFs
type LogItem ¶
type Node ¶
type Node struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
Name string `json:"name" bson:"name"`
Status string `json:"status" bson:"status"`
Ip string `json:"ip" bson:"ip"`
Port string `json:"port" bson:"port"`
Mac string `json:"mac" bson:"mac"`
Hostname string `json:"hostname" bson:"hostname"`
Description string `json:"description" bson:"description"`
// 用于唯一标识节点,可能是mac地址,可能是ip地址
Key string `json:"key" bson:"key"`
// 前端展示
IsMaster bool `json:"is_master" bson:"is_master"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTsUnix int64 `json:"update_ts_unix" bson:"update_ts_unix"`
}
type Project ¶
type Project struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
Name string `json:"name" bson:"name"`
Description string `json:"description" bson:"description"`
Tags []string `json:"tags" bson:"tags"`
// 前端展示
Spiders []Spider `json:"spiders" bson:"spiders"`
Username string `json:"username" bson:"username"`
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetProjectList ¶
func (*Project) GetSpiders ¶
type Schedule ¶
type Schedule struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
Name string `json:"name" bson:"name"`
Description string `json:"description" bson:"description"`
SpiderId bson.ObjectId `json:"spider_id" bson:"spider_id"`
Cron string `json:"cron" bson:"cron"`
EntryId cron.EntryID `json:"entry_id" bson:"entry_id"`
Param string `json:"param" bson:"param"`
RunType string `json:"run_type" bson:"run_type"`
NodeIds []bson.ObjectId `json:"node_ids" bson:"node_ids"`
Status string `json:"status" bson:"status"`
Enabled bool `json:"enabled" bson:"enabled"`
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
ScrapySpider string `json:"scrapy_spider" bson:"scrapy_spider"`
ScrapyLogLevel string `json:"scrapy_log_level" bson:"scrapy_log_level"`
// 前端展示
SpiderName string `json:"spider_name" bson:"spider_name"`
Username string `json:"user_name" bson:"user_name"`
Nodes []Node `json:"nodes" bson:"nodes"`
Message string `json:"message" bson:"message"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetScheduleList ¶
type SecuritySetting ¶
type SecuritySetting struct {
EnableRegister bool
EnableInvitation bool
DocumentMeta `bson:"inline" json:"inline"`
}
demo
func GetSecuritySetting ¶
func GetSecuritySetting() (SecuritySetting, error)
type Spider ¶
type Spider struct {
Id bson.ObjectId `json:"_id" bson:"_id"` // 爬虫ID
Name string `json:"name" bson:"name"` // 爬虫名称(唯一)
DisplayName string `json:"display_name" bson:"display_name"` // 爬虫显示名称
Type string `json:"type" bson:"type"` // 爬虫类别
FileId bson.ObjectId `json:"file_id" bson:"file_id"` // GridFS文件ID
Col string `json:"col" bson:"col"` // 结果储存位置
Site string `json:"site" bson:"site"` // 爬虫网站
Envs []Env `json:"envs" bson:"envs"` // 环境变量
Remark string `json:"remark" bson:"remark"` // 备注
Src string `json:"src" bson:"src"` // 源码位置
ProjectId bson.ObjectId `json:"project_id" bson:"project_id"` // 项目ID
IsPublic bool `json:"is_public" bson:"is_public"` // 是否公开
// 自定义爬虫
Cmd string `json:"cmd" bson:"cmd"` // 执行命令
// Scrapy 爬虫(属于自定义爬虫)
IsScrapy bool `json:"is_scrapy" bson:"is_scrapy"` // 是否为 Scrapy 爬虫
SpiderNames []string `json:"spider_names" bson:"spider_names"` // 爬虫名称列表
// 可配置爬虫
Template string `json:"template" bson:"template"` // Spiderfile模版
// Git 设置
IsGit bool `json:"is_git" bson:"is_git"` // 是否为 Git
GitUrl string `json:"git_url" bson:"git_url"` // Git URL
GitBranch string `json:"git_branch" bson:"git_branch"` // Git 分支
GitHasCredential bool `json:"git_has_credential" bson:"git_has_credential"` // Git 是否加密
GitUsername string `json:"git_username" bson:"git_username"` // Git 用户名
GitPassword string `json:"git_password" bson:"git_password"` // Git 密码
GitAutoSync bool `json:"git_auto_sync" bson:"git_auto_sync"` // Git 是否自动同步
GitSyncFrequency string `json:"git_sync_frequency" bson:"git_sync_frequency"` // Git 同步频率
GitSyncError string `json:"git_sync_error" bson:"git_sync_error"` // Git 同步错误
// 长任务
IsLongTask bool `json:"is_long_task" bson:"is_long_task"` // 是否为长任务
// 去重
IsDedup bool `json:"is_dedup" bson:"is_dedup"` // 是否去重
DedupField string `json:"dedup_field" bson:"dedup_field"` // 去重字段
DedupMethod string `json:"dedup_method" bson:"dedup_method"` // 去重方式
// Web Hook
IsWebHook bool `json:"is_web_hook" bson:"is_web_hook"` // 是否开启 Web Hook
WebHookUrl string `json:"web_hook_url" bson:"web_hook_url"` // Web Hook URL
// 前端展示
LastRunTs time.Time `json:"last_run_ts"` // 最后一次执行时间
LastStatus string `json:"last_status"` // 最后执行状态
Config entity.ConfigSpiderData `json:"config"` // 可配置爬虫配置
LatestTasks []Task `json:"latest_tasks"` // 最近任务列表
Username string `json:"username"` // 用户名称
ProjectName string `json:"project_name"` // 项目名称
// 时间
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetSpiderAllList ¶
获取所有爬虫列表
func GetSpiderList ¶
获取爬虫列表
func (*Spider) GetLatestTasks ¶
爬虫正在运行的任务
type Task ¶
type Task struct {
Id string `json:"_id" bson:"_id"`
SpiderId bson.ObjectId `json:"spider_id" bson:"spider_id"`
StartTs time.Time `json:"start_ts" bson:"start_ts"`
FinishTs time.Time `json:"finish_ts" bson:"finish_ts"`
Status string `json:"status" bson:"status"`
NodeId bson.ObjectId `json:"node_id" bson:"node_id"`
LogPath string `json:"log_path" bson:"log_path"`
Cmd string `json:"cmd" bson:"cmd"`
Param string `json:"param" bson:"param"`
Error string `json:"error" bson:"error"`
ResultCount int `json:"result_count" bson:"result_count"`
ErrorLogCount int `json:"error_log_count" bson:"error_log_count"`
WaitDuration float64 `json:"wait_duration" bson:"wait_duration"`
RuntimeDuration float64 `json:"runtime_duration" bson:"runtime_duration"`
TotalDuration float64 `json:"total_duration" bson:"total_duration"`
Pid int `json:"pid" bson:"pid"`
RunType string `json:"run_type" bson:"run_type"`
ScheduleId bson.ObjectId `json:"schedule_id" bson:"schedule_id"`
Type string `json:"type" bson:"type"`
// 前端数据
SpiderName string `json:"spider_name"`
NodeName string `json:"node_name"`
Username string `json:"username"`
NodeIds []string `json:"node_ids"`
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetTaskList ¶
func (*Task) GetErrorLogItems ¶
func (t *Task) GetErrorLogItems(n int) (errLogItems []ErrorLogItem, err error)
func (*Task) GetLogItems ¶
func (*Task) GetResults ¶
type TaskDailyItem ¶
type TaskDailyItem struct {
Date string `json:"date" bson:"_id"`
TaskCount int `json:"task_count" bson:"task_count"`
AvgRuntimeDuration float64 `json:"avg_runtime_duration" bson:"avg_runtime_duration"`
}
func GetDailyTaskStats ¶
func GetDailyTaskStats(query bson.M) ([]TaskDailyItem, error)
type Token ¶
type User ¶
type User struct {
Id bson.ObjectId `json:"_id" bson:"_id"`
Username string `json:"username" bson:"username"`
Password string `json:"password" bson:"password"`
Role string `json:"role" bson:"role"`
Email string `json:"email" bson:"email"`
Setting UserSetting `json:"setting" bson:"setting"`
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
}
func GetUserByUsername ¶
func GetUserList ¶
type UserSetting ¶
type UserSetting struct {
NotificationTrigger string `json:"notification_trigger" bson:"notification_trigger"`
DingTalkRobotWebhook string `json:"ding_talk_robot_webhook" bson:"ding_talk_robot_webhook"`
WechatRobotWebhook string `json:"wechat_robot_webhook" bson:"wechat_robot_webhook"`
EnabledNotifications []string `json:"enabled_notifications" bson:"enabled_notifications"`
ErrorRegexPattern string `json:"error_regex_pattern" bson:"error_regex_pattern"`
MaxErrorLog int `json:"max_error_log" bson:"max_error_log"`
LogExpireDuration int64 `json:"log_expire_duration" bson:"log_expire_duration"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.