@@ -28,6 +28,10 @@ import (
2828 "github.com/sirupsen/logrus"
2929)
3030
31+ /*
32+ * @Description: ScheduleBl is the scheduler business logic.
33+ * @Note: This is the main scheduler business logic.
34+ */
3135type ScheduleBl struct {
3236 structure.MutexLocker
3337 // resource management
@@ -46,6 +50,10 @@ type ScheduleBl struct {
4650 softSchedule bool
4751}
4852
53+ /*
54+ * @Description: Init initializes the ScheduleBl.
55+ * @Note: This function will initialize the ScheduleBl.
56+ */
4957func (s * ScheduleBl ) Init () {
5058 logrus .Info ("Initializing ScheduleBl..." )
5159 s .LoadConfig ()
@@ -64,6 +72,10 @@ func (s *ScheduleBl) Init() {
6472 go s .waitingStartedTask ()
6573}
6674
75+ /*
76+ * @Description: LoadConfig loads the configuration from the common package.
77+ * @Note: This function will load the configuration from the common package.
78+ */
6779func (s * ScheduleBl ) LoadConfig () {
6880 // Load configuration from common package
6981
@@ -102,6 +114,10 @@ func (s *ScheduleBl) LoadConfig() {
102114 s .startChanSize , s .tickerInterval , s .softSchedule )
103115}
104116
117+ /*
118+ * @Description: startTicker starts the ticker.
119+ * @Note: This function will start the ticker.
120+ */
105121func (s * ScheduleBl ) startTicker () {
106122 // Create a ticker with the specified interval
107123 ticker := time .Tick (time .Duration (s .tickerInterval ) * time .Second )
@@ -113,6 +129,11 @@ func (s *ScheduleBl) startTicker() {
113129}
114130
115131// this make scheduler manager try to schedule next tasks
132+ /*
133+ * @Description: TryScheduleNextTasks tries to schedule the next tasks.
134+ * @Note: This function will try to schedule the next tasks.
135+ * @Param noLock
136+ */
116137func (s * ScheduleBl ) TryScheduleNextTasks (noLock ... bool ) {
117138 defer func () {
118139 if err := recover (); err != nil {
@@ -126,6 +147,12 @@ func (s *ScheduleBl) TryScheduleNextTasks(noLock ...bool) {
126147}
127148
128149// Main routine to schedule tasks
150+ /*
151+ * @Description: tryScheduleInner tries to schedule the next tasks.
152+ * @Note: This function will try to schedule the next tasks.
153+ * @Param softSchedule
154+ * @Param noLock
155+ */
129156func (s * ScheduleBl ) tryScheduleInner (softSchedule bool , noLock ... bool ) error {
130157 // Implement logic to get the next task in the queue for the given space
131158 if ! (len (noLock ) > 0 && noLock [0 ]) {
@@ -183,6 +210,12 @@ func (s *ScheduleBl) tryScheduleInner(softSchedule bool, noLock ...bool) error {
183210
184211// QueueTask Add the task to the inner queue.
185212// If the task exists, return false.
213+ /*
214+ * @Description: QueueTask queues the task.
215+ * @Note: This function will queue the task.
216+ * @Param taskInfo
217+ * @Return bool, error
218+ */
186219func (s * ScheduleBl ) QueueTask (taskInfo * structure.TaskInfo ) (bool , error ) {
187220 if taskInfo == nil {
188221 return false , errors .New ("the argument `taskInfo` is nil" )
@@ -231,6 +264,12 @@ func (s *ScheduleBl) QueueTask(taskInfo *structure.TaskInfo) (bool, error) {
231264 return ok , nil
232265}
233266
267+ /*
268+ * @Description: QueueTaskFromTemplate queues the task from the template.
269+ * @Note: This function will queue the task from the template. This function is used by cron tasks.
270+ * @Param template
271+ * @Return int32, error
272+ */
234273func (s * ScheduleBl ) QueueTaskFromTemplate (template * structure.TaskInfo ) (int32 , error ) {
235274 if template == nil {
236275 return - 1 , errors .New ("the argument `template` is nil" )
@@ -255,6 +294,12 @@ func (s *ScheduleBl) QueueTaskFromTemplate(template *structure.TaskInfo) (int32,
255294 return taskInfo .ID , nil
256295}
257296
297+ /*
298+ * @Description: BatchQueueTask batches the task.
299+ * @Note: This function will batch the task.
300+ * @Param taskInfos
301+ * @Return []bool, []error
302+ */
258303func (s * ScheduleBl ) BatchQueueTask (taskInfos []* structure.TaskInfo ) ([]bool , []error ) {
259304 if len (taskInfos ) == 0 {
260305 return []bool {}, []error {}
@@ -281,7 +326,6 @@ func (s *ScheduleBl) BatchQueueTask(taskInfos []*structure.TaskInfo) ([]bool, []
281326}
282327
283328// ******** CloseCurrent ********
284-
285329func (s * ScheduleBl ) CloseCurrent (taskId int32 , removeWorkerName ... string ) error {
286330 defer s .Unlock (s .Lock ())
287331
@@ -307,6 +351,8 @@ func (s *ScheduleBl) CloseCurrent(taskId int32, removeWorkerName ...string) erro
307351 return nil
308352}
309353
354+ // This will be called when a worker is offline.
355+ // This will be called when a worker is online.
310356func (s * ScheduleBl ) ChangeWorkerStatus (workerName string , status schedules.WorkerOngoingStatus ) (bool , error ) {
311357 defer s .Unlock (s .Lock ())
312358 s .resourceManager .ChangeWorkerStatus (workerName , status )
@@ -406,7 +452,7 @@ func (s *ScheduleBl) startWaitingTask(agent *schedules.Agent, taskInfo *structur
406452
407453// ********* CANCEL TASK ********
408454// handle cancel task
409-
455+ // need to cancel cron task
410456func (s * ScheduleBl ) CancelTask (taskInfo * structure.TaskInfo ) error {
411457 if taskInfo == nil {
412458 return errors .New ("the argument `taskInfo` is nil" )
0 commit comments