mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-23 17:31:11 +01:00
fix
This commit is contained in:
@@ -18,12 +18,12 @@ 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"` // 爬虫类别
|
||||
Type string `json:"type" bson:"type"` // 爬虫类别
|
||||
FileId bson.ObjectId `json:"file_id" bson:"file_id"` // GridFS文件ID
|
||||
Col string `json:"col"` // 结果储存位置
|
||||
Site string `json:"site"` // 爬虫网站
|
||||
Col string `json:"col" bson:"col"` // 结果储存位置
|
||||
Site string `json:"site" bson:"site"` // 爬虫网站
|
||||
Envs []Env `json:"envs" bson:"envs"` // 环境变量
|
||||
Remark string `json:"remark"` // 备注
|
||||
Remark string `json:"remark" bson:"remark"` // 备注
|
||||
// 自定义爬虫
|
||||
Src string `json:"src" bson:"src"` // 源码位置
|
||||
Cmd string `json:"cmd" bson:"cmd"` // 执行命令
|
||||
@@ -130,7 +130,7 @@ func GetSpiderByName(name string) *Spider {
|
||||
|
||||
var result *Spider
|
||||
if err := c.Find(bson.M{"name": name}).One(result); err != nil {
|
||||
log.Errorf("get spider error: %s", err.Error())
|
||||
log.Errorf("get spider error: %s, spider_name: %s", err.Error(), name)
|
||||
debug.PrintStack()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ func (s *SpiderSync) Download() {
|
||||
// 解压缩临时文件到目标文件夹
|
||||
dstPath := filepath.Join(
|
||||
viper.GetString("spider.path"),
|
||||
s.Spider.Name,
|
||||
)
|
||||
if err := utils.DeCompress(tmpFile, dstPath); err != nil {
|
||||
log.Errorf(err.Error())
|
||||
|
||||
@@ -2,18 +2,52 @@ package spider_handler
|
||||
|
||||
import (
|
||||
"crawlab/config"
|
||||
"crawlab/database"
|
||||
"crawlab/model"
|
||||
"github.com/apex/log"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var s SpiderSync
|
||||
|
||||
func init() {
|
||||
if err := config.InitConfig("../../conf/config.yml"); err != nil {
|
||||
log.Fatal("Init config failed")
|
||||
}
|
||||
log.Infof("初始化配置成功")
|
||||
|
||||
// 初始化Mongodb数据库
|
||||
if err := database.InitMongo(); err != nil {
|
||||
log.Error("init mongodb error:" + err.Error())
|
||||
debug.PrintStack()
|
||||
panic(err)
|
||||
}
|
||||
log.Info("初始化Mongodb数据库成功")
|
||||
|
||||
// 初始化Redis数据库
|
||||
if err := database.InitRedis(); err != nil {
|
||||
log.Error("init redis error:" + err.Error())
|
||||
debug.PrintStack()
|
||||
panic(err)
|
||||
}
|
||||
log.Info("初始化Redis数据库成功")
|
||||
|
||||
s = SpiderSync{
|
||||
Spider: model.Spider{
|
||||
Id: bson.ObjectIdHex("5d8d5e4b44500b000150009c"),
|
||||
Name: "scrapy-pre_sale",
|
||||
FileId: bson.ObjectIdHex("5d8d5e4b44500b0001500098"),
|
||||
Src: "/opt/crawlab/spiders/scrapy-pre_sale",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpiderSync_CreateMd5File(t *testing.T) {
|
||||
s := SpiderSync{}
|
||||
s.CreateMd5File("asssss", "gongyu_abc")
|
||||
s.CreateMd5File("this is md5")
|
||||
}
|
||||
|
||||
func TestSpiderSync_Download(t *testing.T) {
|
||||
s.Download()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user