job.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. package dao
  2. import (
  3. "runtime/debug"
  4. "bet24.com/database"
  5. "bet24.com/log"
  6. )
  7. // 作业列表
  8. type (
  9. jobList_in struct {
  10. DataBaseName string //数据库名称
  11. }
  12. jobInfo struct {
  13. Database_name string //数据库名称
  14. Name string //作业名称
  15. JobEnabled string //作业是否启用
  16. Step_name string //作业步骤名称
  17. Command string //执行命令
  18. Last_run_time string //上一次执行间
  19. ScheduleEnabled string //步骤是否启用
  20. Freq_type string //作业运行的频率
  21. Freq_subday_type string //每天频率类型
  22. Description string //作业描述
  23. }
  24. jobList_out struct {
  25. RecordCount int //记录数
  26. List []jobInfo
  27. }
  28. jobList struct {
  29. database.Trans_base
  30. In jobList_in
  31. Out jobList_out
  32. }
  33. )
  34. func NewJobList() *jobList {
  35. return &jobList{}
  36. }
  37. func (this *jobList) DoAction(ch chan<- interface{}) {
  38. defer func() {
  39. if err := recover(); err != nil {
  40. log.Release("transaction recover fail %v", err)
  41. log.Release("%s", debug.Stack())
  42. }
  43. if ch != nil {
  44. ch <- this
  45. }
  46. }()
  47. statement := database.NewStatement()
  48. statement.SetNeedReturnValue(false)
  49. statement.SetOpenRecordSet(true)
  50. statement.SetProcName("MSDB_SysJobs_GetList")
  51. statement.AddParamter("@DataBaseName", database.AdParamInput, database.AdVarChar, 32, this.In.DataBaseName)
  52. sqlstring := statement.GenSql()
  53. retRows := MSDB.ExecSql(sqlstring)
  54. rowLen := len(retRows)
  55. if rowLen <= 0 {
  56. this.State = false
  57. return
  58. }
  59. this.State = true
  60. this.Out.List = make([]jobInfo, rowLen)
  61. for i := 0; i < rowLen; i++ {
  62. ret := retRows[i]
  63. out := &this.Out.List[i]
  64. out.Database_name = (*ret[0].(*interface{})).(string)
  65. out.Name = (*ret[1].(*interface{})).(string)
  66. out.JobEnabled = (*ret[2].(*interface{})).(string)
  67. out.Step_name = (*ret[3].(*interface{})).(string)
  68. out.Command = (*ret[4].(*interface{})).(string)
  69. out.Last_run_time = (*ret[5].(*interface{})).(string)
  70. out.ScheduleEnabled = (*ret[6].(*interface{})).(string)
  71. out.Freq_type = (*ret[7].(*interface{})).(string)
  72. out.Freq_subday_type = (*ret[8].(*interface{})).(string)
  73. out.Description = (*ret[9].(*interface{})).(string)
  74. }
  75. }
  76. // 作业简单列表
  77. type (
  78. jobSimpleList_in struct {
  79. DataBaseName string //数据库名称
  80. }
  81. jobSimpleInfo struct {
  82. Name string //作业名称
  83. }
  84. jobSimpleList_out struct {
  85. RecordCount int //记录数
  86. List []jobSimpleInfo
  87. }
  88. jobSimpleList struct {
  89. database.Trans_base
  90. In jobList_in
  91. Out jobList_out
  92. }
  93. )
  94. func NewJobSimpleList() *jobSimpleList {
  95. return &jobSimpleList{}
  96. }
  97. func (this *jobSimpleList) DoAction(ch chan<- interface{}) {
  98. defer func() {
  99. if err := recover(); err != nil {
  100. log.Release("transaction recover fail %v", err)
  101. log.Release("%s", debug.Stack())
  102. }
  103. if ch != nil {
  104. ch <- this
  105. }
  106. }()
  107. statement := database.NewStatement()
  108. statement.SetNeedReturnValue(false)
  109. statement.SetOpenRecordSet(true)
  110. statement.SetProcName("MSDB_SysJobs_GetSimplyList")
  111. statement.AddParamter("@DataBaseName", database.AdParamInput, database.AdVarChar, 32, this.In.DataBaseName)
  112. sqlstring := statement.GenSql()
  113. retRows := MSDB.ExecSql(sqlstring)
  114. rowLen := len(retRows)
  115. if rowLen <= 0 {
  116. this.State = false
  117. return
  118. }
  119. this.State = true
  120. this.Out.List = make([]jobInfo, rowLen)
  121. for i := 0; i < rowLen; i++ {
  122. ret := retRows[i]
  123. out := &this.Out.List[i]
  124. out.Name = (*ret[0].(*interface{})).(string)
  125. }
  126. }
  127. // 作业历史列表
  128. type (
  129. jobHistoryList_in struct {
  130. DataBaseName string //数据库名称
  131. JobName string //作业名称
  132. RunStatus int //运行失败的作业 -1=所有对象
  133. PageIndex int //页索引
  134. PageSize int //页大小
  135. }
  136. jobHistoryInfo struct {
  137. Database_name string //数据库名称
  138. Job_name string //作业名称
  139. Message string //消息
  140. Step_id int //作业中步骤的ID
  141. Run_status bool //执行状态
  142. Command string //执行命令
  143. Run_duration string //运行时间
  144. Retries_attempted int //重试次数
  145. Run_time string //运行时间
  146. }
  147. jobHistoryList_out struct {
  148. RecordCount int //记录数
  149. List []jobHistoryInfo
  150. }
  151. jobHistoryList struct {
  152. database.Trans_base
  153. In jobHistoryList_in
  154. Out jobHistoryList_out
  155. }
  156. )
  157. func NewJobHistoryList() *jobHistoryList {
  158. return &jobHistoryList{}
  159. }
  160. func (this *jobHistoryList) DoAction(ch chan<- interface{}) {
  161. defer func() {
  162. if err := recover(); err != nil {
  163. log.Release("transaction recover fail %v", err)
  164. log.Release("%s", debug.Stack())
  165. }
  166. if ch != nil {
  167. ch <- this
  168. }
  169. }()
  170. statement := database.NewStatement()
  171. statement.SetNeedReturnValue(false)
  172. statement.SetOpenRecordSet(true)
  173. statement.SetProcName("MSDB_SysJobHistory_GetList")
  174. statement.AddParamter("@DataBaseName", database.AdParamInput, database.AdVarChar, 32, this.In.DataBaseName)
  175. statement.AddParamter("@JobName", database.AdParamInput, database.AdNVarChar, 32, this.In.JobName)
  176. statement.AddParamter("@RunStatus", database.AdParamInput, database.AdInteger, 4, this.In.RunStatus)
  177. statement.AddParamter("@PageIndex", database.AdParamInput, database.AdInteger, 4, this.In.PageIndex)
  178. statement.AddParamter("@PageSize", database.AdParamInput, database.AdInteger, 4, this.In.PageSize)
  179. statement.AddParamter("@RecordCount", database.AdParamOutput, database.AdInteger, 4, this.Out.RecordCount)
  180. sqlstring := statement.GenSql()
  181. retRows := MSDB.ExecSql(sqlstring)
  182. rowLen := len(retRows)
  183. if rowLen <= 0 {
  184. this.State = false
  185. return
  186. }
  187. this.State = true
  188. if rowLen > 1 {
  189. this.Out.List = make([]jobHistoryInfo, rowLen-1)
  190. for i := 0; i < rowLen-1; i++ {
  191. ret := retRows[i]
  192. out := &this.Out.List[i]
  193. out.Database_name = (*ret[0].(*interface{})).(string)
  194. out.Job_name = (*ret[1].(*interface{})).(string)
  195. out.Message = (*ret[2].(*interface{})).(string)
  196. out.Step_id = int((*ret[3].(*interface{})).(int64))
  197. out.Run_status = (*ret[4].(*interface{})).(bool)
  198. out.Command = (*ret[5].(*interface{})).(string)
  199. out.Run_duration = (*ret[6].(*interface{})).(string)
  200. out.Retries_attempted = int((*ret[7].(*interface{})).(int64))
  201. out.Run_time = (*ret[8].(*interface{})).(string)
  202. }
  203. }
  204. this.Out.RecordCount = int((*retRows[rowLen-1][0].(*interface{})).(int64))
  205. }