mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-02-04 06:54:41 +08:00
failure record
This commit is contained in:
@@ -25,9 +25,10 @@
|
|||||||
|
|
||||||
|
|
||||||
--bg-light: #ffffff;
|
--bg-light: #ffffff;
|
||||||
|
|
||||||
--bg-dark: #21252b;
|
--bg-dark: #21252b;
|
||||||
|
|
||||||
|
--active--text-color: #ffb22cd6;
|
||||||
|
--active--bg-color: #ffb22c0d;
|
||||||
|
|
||||||
--text-color-primary: #ffffff;
|
--text-color-primary: #ffffff;
|
||||||
--content-text-color: #888888;
|
--content-text-color: #888888;
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ onMounted(() => {
|
|||||||
.c_nav {
|
.c_nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
|
border-bottom: 2px solid rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.c_nav_text {
|
.c_nav_text {
|
||||||
@@ -87,8 +87,14 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c_nav_more {
|
.c_nav_more {
|
||||||
background: #25252b;
|
border-radius: 5px;
|
||||||
border-radius: 8px;
|
background: linear-gradient(#ffffff15, #ffffff1a);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c_nav_more:hover {
|
||||||
|
color: var(--active--text-color);
|
||||||
|
background-color: var(--active--bg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.content > div {
|
.content > div {
|
||||||
|
|||||||
@@ -7,32 +7,32 @@ import {ElementPlusResolver} from "unplugin-vue-components/resolvers";
|
|||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
// 本地测试环境
|
// 本地测试环境
|
||||||
// server: {
|
|
||||||
// host: '0.0.0.0',
|
|
||||||
// port: 3600,
|
|
||||||
// proxy: {
|
|
||||||
// "/api": {
|
|
||||||
// // target: `http://127.0.0.1:3601`,
|
|
||||||
// target: `http://113.44.5.201:3601`,
|
|
||||||
// changeOrigin: true, // 允许跨域
|
|
||||||
// rewrite: path => path.replace(/^\/api/, '')
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
|
|
||||||
// nginx发布构建时使用此配置
|
|
||||||
server: {
|
server: {
|
||||||
host: 'localhost',
|
host: '0.0.0.0',
|
||||||
port: 3600,
|
port: 3600,
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api": {
|
"/api": {
|
||||||
target: `http://localhost`,
|
target: `http://127.0.0.1:3601`,
|
||||||
|
// target: `http://113.44.5.201:3601`,
|
||||||
changeOrigin: true, // 允许跨域
|
changeOrigin: true, // 允许跨域
|
||||||
rewrite: path => path.replace(/^\/api/,'')
|
rewrite: path => path.replace(/^\/api/, '')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// nginx发布构建时使用此配置
|
||||||
|
// server: {
|
||||||
|
// host: 'localhost',
|
||||||
|
// port: 3600,
|
||||||
|
// proxy: {
|
||||||
|
// "/api": {
|
||||||
|
// target: `http://localhost`,
|
||||||
|
// changeOrigin: true, // 允许跨域
|
||||||
|
// rewrite: path => path.replace(/^\/api/,'')
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
AutoImport({
|
AutoImport({
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ const (
|
|||||||
// DefaultUpdateTime 每次采集最近 3 小时内更新的影片
|
// DefaultUpdateTime 每次采集最近 3 小时内更新的影片
|
||||||
DefaultUpdateTime = 3
|
DefaultUpdateTime = 3
|
||||||
|
|
||||||
// FailureCollectKey 失败采集记录key
|
// FailureAllCollectKey 失败采集记录-全量采集记录
|
||||||
FailureCollectKey = "CollectRecord:Fail:%d"
|
FailureAllCollectKey = "CollectRecord:Fail:%s"
|
||||||
|
// FailureUpdateCollectKey 失败采集记录-更新失败记录
|
||||||
|
FailureUpdateCollectKey = "CollectRecord:Fail:%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
// -------------------------Web API相关redis key-----------------------------------
|
// -------------------------Web API相关redis key-----------------------------------
|
||||||
@@ -85,10 +87,11 @@ const (
|
|||||||
// -------------------------Database Connection Params-----------------------------------
|
// -------------------------Database Connection Params-----------------------------------
|
||||||
const (
|
const (
|
||||||
// SearchTableName 存放检索信息的数据表名
|
// SearchTableName 存放检索信息的数据表名
|
||||||
SearchTableName = "search"
|
SearchTableName = "search"
|
||||||
UserTableName = "users"
|
UserTableName = "users"
|
||||||
UserIdInitialVal = 10000
|
UserIdInitialVal = 10000
|
||||||
FileTableName = "files"
|
FileTableName = "files"
|
||||||
|
FailureRecordTableName = "failure_records"
|
||||||
|
|
||||||
//mysql服务配置信息 root:root 设置mysql账户的用户名和密码
|
//mysql服务配置信息 root:root 设置mysql账户的用户名和密码
|
||||||
|
|
||||||
|
|||||||
76
server/model/system/CollectRecord.go
Normal file
76
server/model/system/CollectRecord.go
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"log"
|
||||||
|
"server/config"
|
||||||
|
"server/plugin/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FailureRecord 失败采集记录信息机构体
|
||||||
|
type FailureRecord struct {
|
||||||
|
gorm.Model
|
||||||
|
OriginId string `json:"originId"` // 采集站唯一ID
|
||||||
|
Uri string `json:"uri"` // 采集源链接
|
||||||
|
CollectType ResourceType `json:"collectType"` // 采集类型
|
||||||
|
PageNumber int `json:"pageNumber"` // 页码
|
||||||
|
Hour int `json:"hour"` // 采集参数 h 时长
|
||||||
|
Cause string `json:"cause"` // 失败原因
|
||||||
|
Status int `json:"status"` // 重试状态
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName 采集失败记录表表名
|
||||||
|
func (fr FailureRecord) TableName() string {
|
||||||
|
return config.FailureRecordTableName
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFailureRecordTable 创建失效记录表
|
||||||
|
func CreateFailureRecordTable() {
|
||||||
|
var fl = &FailureRecord{}
|
||||||
|
// 不存在则创建FailureRecord表
|
||||||
|
if !db.Mdb.Migrator().HasTable(fl) {
|
||||||
|
if err := db.Mdb.AutoMigrate(fl); err != nil {
|
||||||
|
log.Println("Create Table failure_record failed:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveFailureRecord 添加采集失效记录
|
||||||
|
func SaveFailureRecord(fl FailureRecord) {
|
||||||
|
if err := db.Mdb.Create(&fl).Error; err != nil {
|
||||||
|
log.Println("Add failure record failed:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FailureRecordList 获取所有的采集失效记录
|
||||||
|
func FailureRecordList(page *Page) []FailureRecord {
|
||||||
|
var count int64
|
||||||
|
db.Mdb.Model(&FailureRecord{}).Count(&count)
|
||||||
|
page.Total = int(count)
|
||||||
|
page.PageCount = int((page.Total + page.PageSize - 1) / page.PageSize)
|
||||||
|
// 获取分页查询的数据
|
||||||
|
var list []FailureRecord
|
||||||
|
if err := db.Mdb.Limit(page.PageSize).Offset((page.Current - 1) * page.PageSize).Find(&list).Error; err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindRecordById 获取id对应的失效记录
|
||||||
|
func FindRecordById(id uint) *FailureRecord {
|
||||||
|
var fr FailureRecord
|
||||||
|
fr.ID = id
|
||||||
|
// 通过ID查询对应的数据
|
||||||
|
db.Mdb.First(fr)
|
||||||
|
return &fr
|
||||||
|
}
|
||||||
|
|
||||||
|
// RetryRecord 修改重试采集成功的记录
|
||||||
|
func RetryRecord(id uint, status int64) error {
|
||||||
|
// 查询id对应的失败记录
|
||||||
|
fr := FindRecordById(id)
|
||||||
|
// 将本次更新成功的记录数据状态修改为成功 0
|
||||||
|
return db.Mdb.Model(&FailureRecord{}).Where("update_at > ?", fr.UpdatedAt).Update("status", 0).Error
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"server/config"
|
"server/config"
|
||||||
"server/plugin/common/util"
|
"server/plugin/common/util"
|
||||||
"server/plugin/db"
|
"server/plugin/db"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -72,16 +71,6 @@ type FilmSource struct {
|
|||||||
Interval int `json:"interval"` // 采集时间间隔 单位/ms
|
Interval int `json:"interval"` // 采集时间间隔 单位/ms
|
||||||
}
|
}
|
||||||
|
|
||||||
// FailureCollect 失败采集记录信息机构体
|
|
||||||
type FailureCollect struct {
|
|
||||||
Id string `json:"id"` // 采集站唯一ID
|
|
||||||
CollectType ResourceType `json:"collectType"` // 采集类型
|
|
||||||
PageNumber int64 `json:"pageNumber"` // 页码
|
|
||||||
//Hour int64 `json:"hour"` // 采集参数 h 时长
|
|
||||||
Cause string `json:"cause"` // 失败原因
|
|
||||||
Time int `json:"time"` // 采集失败时的时间
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveCollectSourceList 保存采集站Api列表
|
// SaveCollectSourceList 保存采集站Api列表
|
||||||
func SaveCollectSourceList(list []FilmSource) error {
|
func SaveCollectSourceList(list []FilmSource) error {
|
||||||
var zl []redis.Z
|
var zl []redis.Z
|
||||||
@@ -186,22 +175,3 @@ func ExistCollectSourceList() bool {
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectFailRecord 记录采集失败的相关参数信息
|
|
||||||
func CollectFailRecord(fc FailureCollect) error {
|
|
||||||
// 将fc序列化为json格式进行存储
|
|
||||||
m, _ := json.Marshal(fc)
|
|
||||||
// 获取当前的时间戳作为set集合的Score
|
|
||||||
z := redis.Z{Score: float64(time.Now().Unix()), Member: m}
|
|
||||||
return db.Rdb.ZAdd(db.Cxt, config.FailureCollectKey, z).Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCollectFailList 从失败采集记录中读取一部分记录
|
|
||||||
func GetCollectFailList() []FailureCollect {
|
|
||||||
// 获取多条记录, 降低读取频率 or 多次单条读取
|
|
||||||
|
|
||||||
// 一次获取多条记录, 再次执行失败则重新进行记录
|
|
||||||
|
|
||||||
// 读取单条记录, 成功执行则进行记录清除, 否则对其进行保留
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func SaveSearchTag(search SearchInfo) {
|
|||||||
// 获取redis中的searchMap
|
// 获取redis中的searchMap
|
||||||
key := fmt.Sprintf(config.SearchTitle, search.Pid)
|
key := fmt.Sprintf(config.SearchTitle, search.Pid)
|
||||||
searchMap := db.Rdb.HGetAll(db.Cxt, key).Val()
|
searchMap := db.Rdb.HGetAll(db.Cxt, key).Val()
|
||||||
// 是否存储对应分类的map, 如果不存在则缓存一份
|
// 是否存在对应分类的map, 如果不存在则缓存一份
|
||||||
if len(searchMap) == 0 {
|
if len(searchMap) == 0 {
|
||||||
searchMap = make(map[string]string)
|
searchMap = make(map[string]string)
|
||||||
searchMap["Category"] = "类型"
|
searchMap["Category"] = "类型"
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ func TableInIt() {
|
|||||||
system.CreateSearchTable()
|
system.CreateSearchTable()
|
||||||
// 创建图片信息管理表
|
// 创建图片信息管理表
|
||||||
system.CreateFileTable()
|
system.CreateFileTable()
|
||||||
|
// 创建采集失效记录表
|
||||||
|
system.CreateFailureRecordTable()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ func collectFilm(s *system.FilmSource, h, pg int) {
|
|||||||
// 执行采集方法 获取影片详情list
|
// 执行采集方法 获取影片详情list
|
||||||
list, err := spiderCore.GetFilmDetail(r)
|
list, err := spiderCore.GetFilmDetail(r)
|
||||||
if err != nil || len(list) <= 0 {
|
if err != nil || len(list) <= 0 {
|
||||||
|
// 添加采集失败记录
|
||||||
|
fr := system.FailureRecord{OriginId: s.Id, Uri: s.Uri, CollectType: system.CollectVideo, PageNumber: pg, Hour: h, Cause: err.Error(), Status: 1}
|
||||||
|
system.SaveFailureRecord(fr)
|
||||||
log.Println("GetMovieDetail Error: ", err)
|
log.Println("GetMovieDetail Error: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user