49 lines
932 B
Go
49 lines
932 B
Go
|
package plugin
|
||
|
|
||
|
import (
|
||
|
"container/list"
|
||
|
"sync"
|
||
|
|
||
|
"apigo.cc/gojs"
|
||
|
"apigo.cc/gojs/goja"
|
||
|
"github.com/robfig/cron/v3"
|
||
|
)
|
||
|
|
||
|
const pluginName = "task"
|
||
|
|
||
|
type PluginObject struct {
|
||
|
skipCron *cron.Cron
|
||
|
delayCron *cron.Cron
|
||
|
// asyncCron *cron.Cron
|
||
|
stopChan chan struct{}
|
||
|
isStarted bool
|
||
|
lock sync.RWMutex
|
||
|
tasks map[string]*Task
|
||
|
taskData map[string]any
|
||
|
taskDataLock sync.RWMutex
|
||
|
|
||
|
taskList map[string]*list.List
|
||
|
taskListLock sync.RWMutex
|
||
|
}
|
||
|
|
||
|
var _pluginObject = &PluginObject{
|
||
|
tasks: map[string]*Task{},
|
||
|
taskData: map[string]any{},
|
||
|
taskList: map[string]*list.List{},
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
tsCode := gojs.MakeTSCode(_pluginObject)
|
||
|
mappedObj := gojs.ToMap(_pluginObject)
|
||
|
gojs.Register("apigo.cc/gojs/"+pluginName, gojs.Module{
|
||
|
ObjectMaker: func(vm *goja.Runtime) gojs.Map {
|
||
|
return mappedObj
|
||
|
},
|
||
|
OnKill: func() {
|
||
|
_pluginObject.Stop()
|
||
|
},
|
||
|
TsCode: tsCode,
|
||
|
Desc: "task api",
|
||
|
})
|
||
|
}
|