task.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package comm
  2. type TaskState int
  3. const (
  4. BT_STATE_QUITED_CACEL = -1 //loop取消退出
  5. BT_STATE_QUITED_EXCEPTION = -2 //loop异常退出
  6. BT_STATE_QUITED_NORMAL = -3 //loop退出
  7. BT_STATE_INIT = iota + 1 //初始化中
  8. BT_STATE_RUNING //正常运行中
  9. BT_STATE_EXCEPTION_RESTARTING //异常重启中
  10. BT_STATE_NORMAL_RESTARTING //主动重启中
  11. )
  12. type TaskRunCallback func(error)
  13. type Task interface {
  14. GetRuningState() TaskState
  15. CancelRuning()
  16. Restart()
  17. InitTask(interface{})
  18. Run(overCallback TaskRunCallback) error
  19. IsAsync() bool //是否异步任务 同步任务会等待执行完毕直接返回结果,异步任务,开启新线程后执行,不会等待结果
  20. GetNats() *NatsBus
  21. SetNats(*NatsBus)
  22. GetName() string
  23. SetName(string)
  24. GetID() string
  25. SetID(string)
  26. }
  27. type EventTask interface {
  28. Task
  29. RegistorEvent(events string, listen EventListener)
  30. //发送同步事件
  31. EmitEvent(name string, data interface{}) (interface{}, error)
  32. }