镜像自地址
https://github.com/tuna/tunasync.git
已同步 2025-12-06 06:26:46 +00:00
feature(worker): framework of mirror provider
这个提交包含在:
@@ -1,13 +1,93 @@
|
||||
// mirror provider is the wrapper of mirror jobs
|
||||
|
||||
package worker
|
||||
|
||||
// a mirrorProvider instance
|
||||
// mirror provider is the wrapper of mirror jobs
|
||||
|
||||
type providerType uint8
|
||||
|
||||
const (
|
||||
_WorkingDirKey = "working_dir"
|
||||
_LogDirKey = "log_dir"
|
||||
_LogFileKey = "log_file"
|
||||
)
|
||||
|
||||
// A mirrorProvider instance
|
||||
type mirrorProvider interface {
|
||||
// name
|
||||
Name() string
|
||||
|
||||
// TODO: implement Run, Terminate and Hooks
|
||||
// run mirror job
|
||||
Run()
|
||||
// terminate mirror job
|
||||
Terminate()
|
||||
// get context
|
||||
Context()
|
||||
// job hooks
|
||||
Hooks()
|
||||
|
||||
Interval() int
|
||||
|
||||
WorkingDir() string
|
||||
LogDir() string
|
||||
LogFile() string
|
||||
|
||||
// enter context
|
||||
EnterContext() *Context
|
||||
// exit context
|
||||
ExitContext() *Context
|
||||
// return context
|
||||
Context() *Context
|
||||
}
|
||||
|
||||
type baseProvider struct {
|
||||
ctx *Context
|
||||
name string
|
||||
interval int
|
||||
}
|
||||
|
||||
func (p *baseProvider) Name() string {
|
||||
return p.name
|
||||
}
|
||||
|
||||
func (p *baseProvider) EnterContext() *Context {
|
||||
p.ctx = p.ctx.Enter()
|
||||
return p.ctx
|
||||
}
|
||||
|
||||
func (p *baseProvider) ExitContext() *Context {
|
||||
p.ctx, _ = p.ctx.Exit()
|
||||
return p.ctx
|
||||
}
|
||||
|
||||
func (p *baseProvider) Context() *Context {
|
||||
return p.ctx
|
||||
}
|
||||
|
||||
func (p *baseProvider) Interval() int {
|
||||
return p.interval
|
||||
}
|
||||
|
||||
func (p *baseProvider) WorkingDir() string {
|
||||
if v, ok := p.ctx.Get(_WorkingDirKey); ok {
|
||||
if s, ok := v.(string); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
panic("working dir is impossible to be non-exist")
|
||||
}
|
||||
|
||||
func (p *baseProvider) LogDir() string {
|
||||
if v, ok := p.ctx.Get(_LogDirKey); ok {
|
||||
if s, ok := v.(string); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
panic("log dir is impossible to be unavailable")
|
||||
}
|
||||
|
||||
func (p *baseProvider) LogFile() string {
|
||||
if v, ok := p.ctx.Get(_LogFileKey); ok {
|
||||
if s, ok := v.(string); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
panic("log dir is impossible to be unavailable")
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户