-
Notifications
You must be signed in to change notification settings - Fork 36
server
gojuukaze edited this page Aug 27, 2022
·
6 revisions
import "github.com/gojuukaze/YTask/v3"
ser := ytask.Server.NewServer(
ytask.Config.Broker(&broker),
ytask.Config.Backend(&backend),
...
)
Config | require | default | code | other |
---|---|---|---|---|
Broker | * | ytask.Config.Broker | ||
Backend | nil | ytask.Config.Backend | ||
Logger | log.YTaskLogger | ytask.Config.Logger | v2.5+ support | |
Debug | FALSE | ytask.Config.Debug | enable debug | |
StatusExpires | 1day | ytask.Config.StatusExpires | Unit: second, the expiration time of the task status. -1: not expired (some backends may not be supported) | |
ResultExpires | 1day | ytask.Config.ResultExpires | Unit: second, the expiration time of the task result.-1: not expired (some backends may not be supported) | |
DelayServerQueueSize | 20 | ytask.Config.DelayServerQueueSize | Delayed task local queue size | |
EnableDelayServer | false | ytask.Config.EnableDelayServer | enable delayed task |
- For MongoDB backend, the expiration time can only be set when the backend is initialized. For details, see the mongo section
func addFunc(a, b int) (int, bool){
return a+b, true
}
// group1 : group name is also the query name
// add : worker name
// addFunc : worker func
ser.Add("group1", "add", addFunc)
v2.4+
func addFunc(a, b int) (int, bool){
return a+b, true
}
func callbackFunc(a, b int, result *message.Result) {
if result.IsSuccess(){
// do ...
}else {
// do ...
}
}
ser.Add("group1", "add", addFunc, callbackFunc)
// group1 : run group name
// 3 : number of worker goroutine
// false: enableDelayServer
ser.Run("group1", 3, false)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
ser.Shutdown(context.Background())
- requirement: V2.2.0+
ser:= ytask.Server.NewServer(...)
ser.Run("g1", 5)
ser.Run("g2", 5)