models

package
v0.0.0-...-9a229c4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdminStatusNormal   = "enabled"
	AdminStatusDisabled = "disabled"
)
View Source
const (
	MenuStatusEnable  = 1 //菜单显示状态
	MenuStatusDisable = 2 //菜单禁用状态
)

Variables

View Source
var (
	NoticeSettingStatusEnabled  = "enabled"         //启用
	NoticeSettingStatusDisabled = "disabled"        //禁用
	NoticeOptionScrapyd         = "scrapyd_service" //scrapyd服务监控状态
	NoticeOptionTaskFinished    = "task_finished"   //是否监听任务完成
	NoticeOptionTaskError       = "task_error"      //是否监听任务异常
	NoticeSettingWildcards      = map[string][]string{
		NoticeOptionScrapyd:      {"{host}", "{error_time}", "{error_message}"},
		NoticeOptionTaskFinished: {"{job_id}", "{task_id}", "{host}", "{project}", "{version}", "{spider}", "{start_time}", "{end_time}", "{duration_time}"},
		NoticeOptionTaskError:    {"{job_id}", "{task_id}", "{host}", "{project}", "{version}", "{spider}", "{start_time}", "{error_time}", "{duration_time}", "{error_message}"},
	}
)
View Source
var (
	SchedulesTaskStatusEnabled  = "enabled"
	SchedulesTaskStatusDisabled = "disabled"
)
View Source
var (
	ServerStatusNormal      uint8 = 1          //服务器状态正常
	ServerStatusFault       uint8 = 2          //服务器状态故障
	ServerAuthClose         uint8 = 1          //服务器验证关闭
	ServerAuthOpen          uint8 = 2          //服务器验证开启
	ServerMonitorDisabled         = "disabled" //关闭服务器监控
	ServerMonitorEnabled          = "enabled"  //开启服务器监控
	ServerAgentStatusNormal uint8 = 1          //代理状态正常
	ServerAgentStatusFault  uint8 = 2          //代理状态故障
)
View Source
var (
	SpiderStatusNormal  uint8 = 1 //爬虫状态正常
	ServerStatusDiscard uint8 = 2 //爬虫状态废弃
)
View Source
var (
	TaskTypeOnce        uint8 = 1 //一次性任务
	TaskTypeTiming      uint8 = 2 //定时任务
	TaskStatusError           = "error"
	TaskStatusPending         = "pending"
	TaskStatusRunning         = "running"
	TaskStatusCancelled       = "cancelled"
	TaskStatusFinished        = "finished"
)

Status 运行状态 error | pending | running | cancelled | finished

Functions

func InitTables

func InitTables() error

func InitTask

func InitTask()

Types

type Access

type Access struct {
	core.BaseModel `xorm:"-"`
	Id             int
	RoleId         int
	App            string
	Controller     string
	Action         string
	Status         int
}

func (*Access) SetAccessList

func (a *Access) SetAccessList(roleIdList []int) bool

设置用户权限列表

type Admin

type Admin struct {
	core.BaseModel `xorm:"-"`
	Id             int            `json:"id" xorm:"pk autoincr"`
	Username       string         `json:"username" form:"username" binding:"required" xorm:"username"`
	Password       string         `json:"-" form:"password" binding:"required" xorm:"password"`
	Email          string         `json:"email" form:"email" xorm:"email"`
	DisplayName    string         `json:"display_name" xorm:"display_name"`
	Status         string         `json:"status" xorm:"status"`
	CreateTime     core.Timestamp `json:"create_time" xorm:"created"`
}

func (*Admin) Create

func (a *Admin) Create() (int, string)

func (*Admin) Delete

func (a *Admin) Delete(id int) error

func (*Admin) Get

func (a *Admin) Get(id int) bool

func (*Admin) Login

func (a *Admin) Login() (bool, string)

func (*Admin) PageList

func (a *Admin) PageList(page int, pageSize int) ([]Admin, int)

分页列表

func (*Admin) Update

func (a *Admin) Update(id int, data core.B) error

type AdminRole

type AdminRole struct {
	core.BaseModel `xorm:"-"`
	Id             int `json:"id" xorm:"pk autoincr"`
	AdminId        int
	RoleId         int
}

type DingtalkNotice

type DingtalkNotice struct {
	Errcode int
	Errmsg  string
}

type EmailNotice

type EmailNotice struct{}
type Menu struct {
	core.BaseModel `xorm:"-"`
	Id             int    `xorm:"pk autoincr" json:"id" form:"id"`
	Name           string `json:"name" form:"name"`
	ParentId       int    `json:"parent_id" form:"parent_id"`
	App            string `json:"app" form:"app"`
	Controller     string `json:"controller" form:"controller"`
	Action         string `json:"action" form:"action"`
	Parameter      string `json:"parameter" form:"parameter"`
	Icon           string `json:"icon" form:"icon"`
	Status         int    `json:"status" form:"status"`
	ListingOrder   int    `json:"listing_order" form:"listing_order"`
}
func (s *Menu) DeleteById() bool

删除菜单

func (s *Menu) Get(id int) bool

获取菜单信息

func (s *Menu) GetMenuStr() string

获取后台管理员所有用的菜单

func (s *Menu) GetSubMenuStr(items []core.A, str *string)

获取下级菜单字符串

func (s *Menu) Insert() bool

更新数据

func (s *Menu) TreeMenus() []core.A

获取所有菜单

func (s *Menu) Update(id int, data core.A) error
type MenuTree struct {
	FinalMenus []core.A
	// contains filtered or unexported fields
}

属性菜单

func GetMenuTreeInstance

func GetMenuTreeInstance(menus []Menu) MenuTree
func (m *MenuTree) GetTree(parentId int, addSpacer string)

获取树形列表 parentId 父节点id addSpacer 增加的间隔字符

type Notice

type Notice interface {
	// contains filtered or unexported methods
}

type NoticeSetting

type NoticeSetting struct {
	Base  core.BaseModel `json:"-" xorm:"-"`
	Id    int            `json:"id" xorm:"pk autoincr"`
	Name  string         `json:"name"`
	Desc  string         `json:"host" `
	Value string         `json:"value"`
}

func (*NoticeSetting) Find

func (n *NoticeSetting) Find() core.B

func (*NoticeSetting) Update

func (n *NoticeSetting) Update(fields []core.B) bool

type Project

type Project struct {
	Base        core.BaseModel `json:"-" xorm:"-"`
	Id          int            `json:"id" xorm:"pk autoincr"`
	Name        string         `json:"name" xorm:"unique" binding:"required"`
	Desc        string         `json:"desc"`
	LastVersion string         `json:"last_version"`
	CreateTime  core.Timestamp `json:"create_time" xorm:"created"`
	UpdateTime  core.Timestamp `json:"update_time" xorm:"created updated"`
}

func (*Project) Del

func (p *Project) Del(id int) (bool, string)

func (*Project) Find

func (p *Project) Find() []Project

获取所有项目

func (*Project) Get

func (p *Project) Get(id int) bool

根据id获取项目信息

func (*Project) GetPageProjects

func (p *Project) GetPageProjects(serverId int, page int, pageSize int) ([]Project, int)

分页获取项目数据

func (*Project) InsertOne

func (p *Project) InsertOne(relation string, serverIds []int, file *multipart.FileHeader) (bool, string, []string)

func (*Project) Update

func (p *Project) Update(id int, data core.A) error

func (*Project) UpdateServers

func (p *Project) UpdateServers(serverIds []int, file *multipart.FileHeader) (bool, string)

更新关联服务器

func (*Project) UpdateVersion

func (p *Project) UpdateVersion(useHistoryVersion string, version string, file *multipart.FileHeader) (bool, string)

更新项目文件

type ProjectHistory

type ProjectHistory struct {
	Base       core.BaseModel `json:"-" xorm:"-"`
	Id         int            `json:"id" xorm:"pk autoincr"`
	ProjectId  int            `json:"project_id" binding:"required"`
	Version    string         `json:"version"`
	CreateTime core.Timestamp `json:"create_time" xorm:"created"`
}

func (*ProjectHistory) CountByProjectIdAndVersion

func (p *ProjectHistory) CountByProjectIdAndVersion() int

func (*ProjectHistory) FindByProjectId

func (p *ProjectHistory) FindByProjectId() []core.B

根据项目id获取历史版本记录

type ProjectServer

type ProjectServer struct {
	Base       core.BaseModel `json:"-" xorm:"-"`
	Id         int            `json:"id" xorm:"pk autoincr"`
	ProjectId  int            `json:"project_id" binding:"required"`
	ServerId   int            `json:"server_id" binding:"required"`
	CreateTime core.Timestamp `json:"create_time" xorm:"created"`
}

func (*ProjectServer) DelProjectServers

func (p *ProjectServer) DelProjectServers(projectId int, serverIds []int, session *xorm.Session) error

删除项目下制定的服务器列表

func (*ProjectServer) InsertProjectServers

func (p *ProjectServer) InsertProjectServers(projectId int, serverIds []int, session *xorm.Session) error

批量增加项目下的服务器

type SchedulesTask

type SchedulesTask struct {
	Base        core.BaseModel `json:"-" xorm:"-"`
	Id          int            `json:"id" xorm:"pk autoincr"`
	ProjectId   int            `json:"project_id"`
	ProjectName string         `json:"project_name"`
	Version     string         `json:"version"`
	ServerId    int            `json:"server_id"`
	Host        string         `json:"host"`
	SpiderId    int            `json:"spider_id"`
	SpiderName  string         `json:"spider_name"`
	Cron        string         `json:"cronn"`
	Status      string         `json:"status"`
}

func (*SchedulesTask) Del

func (s *SchedulesTask) Del(id int) bool

func (*SchedulesTask) FindPages

func (s *SchedulesTask) FindPages(projectId int, version string, serverId int, status string, page int, pageSize int) ([]core.B, int)

分页获取计划任务列表

func (*SchedulesTask) HaveEnabled

func (s *SchedulesTask) HaveEnabled(projectId int) bool

查询项目下是有正在启用的计划任务

func (*SchedulesTask) HaveEnabledByServer

func (s *SchedulesTask) HaveEnabledByServer(serverId int) bool

func (*SchedulesTask) Inert

func (s *SchedulesTask) Inert(projectId int, projectName string, version string, cron string, spiderList []string, serverList []string) bool

func (*SchedulesTask) InitSchedulesToCron

func (s *SchedulesTask) InitSchedulesToCron() bool

初始化计划任务

func (*SchedulesTask) RunSchedules

func (s *SchedulesTask) RunSchedules()

执行计划任务

func (*SchedulesTask) UpdateStatus

func (s *SchedulesTask) UpdateStatus() bool

修改状态

type Scrapyd

type Scrapyd struct {
	Host     string
	Auth     uint8
	Username string
	Password string
}

func (*Scrapyd) AddVersion

func (s *Scrapyd) AddVersion(project *Project, file *multipart.FileHeader) bool

添加scrapy项目

func (*Scrapyd) Cancel

func (s *Scrapyd) Cancel(projectName string, jobId string) error

取消任务

func (*Scrapyd) DaemonStatus

func (s *Scrapyd) DaemonStatus() error

检查服务是否可用

func (*Scrapyd) DelProject

func (s *Scrapyd) DelProject(projectName string) bool

删除项目

func (*Scrapyd) ListJobs

func (s *Scrapyd) ListJobs(projectName string) (error, map[string][]interface{})

获取制定服务器项目下的任务列表

func (*Scrapyd) ListSpiders

func (s *Scrapyd) ListSpiders(project *Project) (error, []string)

获取项目中所包含的爬虫列表

func (*Scrapyd) Schedule

func (s *Scrapyd) Schedule(projectName string, version string, spiderName string) (error, string)

投递任务

type Server

type Server struct {
	Base            core.BaseModel `json:"-" xorm:"-"`
	Id              int            `json:"id" xorm:"pk autoincr"`
	Alias           string         `json:"alias"`
	Host            string         `json:"host" binding:"required"`
	Username        string         `json:"-"`
	Password        string         `json:"-"`
	Auth            uint8          `json:"auth"`
	Status          uint8          `json:"status"`
	AgentStatus     uint8          `json:"agent_status"`
	Monitor         string         `json:"monitor"`
	MonitorAddress  string         `json:"monitor_address"`
	MonitorUsername string         `json:"monitor_username"`
	MonitorPassword string         `json:"monitor_password"`
	CreateTime      core.Timestamp `json:"create_time" xorm:"created"`
	UpdateTime      core.Timestamp `json:"update_time" xorm:"created updated"`
}

func (*Server) Del

func (s *Server) Del(id int) (bool, string)

func (*Server) DetectionStatus

func (s *Server) DetectionStatus()

检测服务器状态并更新

func (*Server) Find

func (s *Server) Find() []Server

获取所有服务器

func (*Server) FindByIds

func (s *Server) FindByIds(ids []int) []Server

func (*Server) FindByProjectId

func (s *Server) FindByProjectId(projectId int) []Server

根据项目id获取所有服务器

func (*Server) FindByProjectIdNotProject

func (s *Server) FindByProjectIdNotProject(projectId int) []Server

根据项目id获取所有未拥有此项目的服务器

func (*Server) Get

func (s *Server) Get(id int) bool

func (*Server) InsertOne

func (s *Server) InsertOne() (bool, string)

添加服务器

func (*Server) PageList

func (s *Server) PageList(projectId int, page int, pageSize int) ([]Server, int)

分页获取服务器数据

func (*Server) ServerMonitor

func (s *Server) ServerMonitor()

监控服务器状态

func (*Server) Update

func (s *Server) Update(id int, data core.A) error

type ServerMonitor

type ServerMonitor struct {
	Base            core.BaseModel `json:"-" xorm:"-"`
	Id              int            `json:"id" xorm:"pk autoincr"`
	ServerId        int            `json:"server_id"`
	MemTotal        int64          `json:"mem_total"`
	MemAvailable    int64          `json:"mem_available"`
	MemUsed         int64          `json:"mem_used"`
	MemUsedPercent  string         `json:"mem_used_percent"`
	CpuPercent      string         `json:"cpu_percent"`
	CpuCoreCount    int            `json:"cpu_core_count"`
	CpuLoad1        string         `json:"cpu_load1"`
	CpuLoad5        string         `json:"cpu_load5"`
	CpuLoad15       string         `json:"cpu_load15"`
	ProcessCount    int            `json:"process_count"`
	NetSendSpeed    int            `json:"net_send_speed"`
	NetReceiveSpeed int            `json:"net_receive_speed"`
	CreateTime      core.Timestamp `json:"create_time"`
}

func (*ServerMonitor) DelAnHourAgo

func (s *ServerMonitor) DelAnHourAgo()

删除一小时之前的监控数据

func (*ServerMonitor) FindByLastTime

func (s *ServerMonitor) FindByLastTime(serverId int, lastTime int) []core.A

func (*ServerMonitor) InsertOne

func (s *ServerMonitor) InsertOne()

添加服务器监控数据

func (*ServerMonitor) OverviewByIds

func (s *ServerMonitor) OverviewByIds(ids []string) ([]map[string]string, error)

获取服务器性能指标概览

type Spider

type Spider struct {
	Base       core.BaseModel `json:"-" xorm:"-"`
	Id         int            `json:"id" xorm:"pk autoincr"`
	ProjectId  int            `json:"project_id"`
	Name       string         `json:"name"`
	Version    string         `json:"version"`
	Status     uint8          `json:"status"`
	CreateTime core.Timestamp `json:"create_time" xorm:"created"`
}

func (*Spider) CountByProjectId

func (s *Spider) CountByProjectId(projectId int) int

获取项目下爬虫数量

func (*Spider) FindByProjectIdAndVersion

func (s *Spider) FindByProjectIdAndVersion(projectId int, version string) []core.B

func (*Spider) FindBySpiderIds

func (s *Spider) FindBySpiderIds(spiderIds []string) []Spider

func (*Spider) FindPageSpiders

func (s *Spider) FindPageSpiders(projectId int, version string, page int, pageSize int, order string) ([]core.B, int)

分页获取爬虫数据

func (*Spider) UpdateProjectSpiders

func (s *Spider) UpdateProjectSpiders(p *Project, spiderNames []string, session *xorm.Session) bool

更新项目下所有爬虫

type Task

type Task struct {
	Base        core.BaseModel `json:"-" xorm:"-"`
	Id          int            `json:"id" xorm:"pk autoincr"`
	Type        uint8          `json:"type"`
	ProjectId   int            `json:"project_id"`
	ProjectName string         `json:"project_name"`
	Version     string         `json:"version"`
	ServerId    int            `json:"server_id"`
	Host        string         `json:"host"`
	SpiderId    int            `json:"spider_id"`
	SpiderName  string         `json:"spider_name"`
	JobId       string         `json:"job_id"`
	StartTime   core.Timestamp `json:"start_time"`
	EndTime     core.Timestamp `json:"end_time"`
	Status      string         `json:"status"`
}

func (*Task) Cancel

func (t *Task) Cancel(id int) bool

取消单个任务

func (*Task) CancelAll

func (t *Task) CancelAll(projectId int, version string, serverId int, status string) (bool, []string)

func (*Task) CancelMulti

func (t *Task) CancelMulti(ids []string) (bool, []string)

取消多个任务

func (*Task) Del

func (t *Task) Del(id int) bool

删除单个任务

func (*Task) DelAll

func (t *Task) DelAll(projectId int, version string, serverId int, status string) bool

func (*Task) DelMulti

func (t *Task) DelMulti(ids []string) bool

删除多个任务

func (*Task) DetectionStatus

func (t *Task) DetectionStatus()

func (*Task) FindTaskPages

func (t *Task) FindTaskPages(projectId int, version string, serverId int, status string, page int, pageSize int) ([]core.B, int)

分页获取任务列表

func (*Task) HaveRunning

func (t *Task) HaveRunning(projectId int) bool

查询项目下是否有正在运行的爬虫,包括定时任务

func (*Task) HaveRunningByServer

func (t *Task) HaveRunningByServer(serverId int) bool

func (*Task) Inert

func (t *Task) Inert(projectId int, projectName string, version string, spiderList []string, serverList []string) (bool, []string)

func (*Task) InertOne

func (t *Task) InertOne()

func (*Task) RunTask

func (t *Task) RunTask(taskId int)

运行任务

type WorkWeixinNotice

type WorkWeixinNotice struct {
	Errcode int
	Errmsg  string
}

Jump to

Keyboard shortcuts

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