Start to enable all worker
()
| 91 | |
| 92 | // Start to enable all worker |
| 93 | func (q *queue) Start() { |
| 94 | q.routineGroup.Run(func() { |
| 95 | // Resume tasks in DB |
| 96 | if len(q.options.resumeTaskType) > 0 && q.taskClient != nil { |
| 97 | |
| 98 | ctx := context.TODO() |
| 99 | ctx = context.WithValue(ctx, inventory.LoadTaskUser{}, true) |
| 100 | ctx = context.WithValue(ctx, inventory.LoadUserGroup{}, true) |
| 101 | tasks, err := q.taskClient.GetPendingTasks(ctx, q.resumeTaskType...) |
| 102 | if err != nil { |
| 103 | q.logger.Warning("Failed to get pending tasks from DB for given type %v: %s", q.resumeTaskType, err) |
| 104 | } |
| 105 | |
| 106 | resumed := 0 |
| 107 | for _, t := range tasks { |
| 108 | resumedTask, err := NewTaskFromModel(t) |
| 109 | if err != nil { |
| 110 | q.logger.Warning("Failed to resume task %d: %s", t.ID, err) |
| 111 | continue |
| 112 | } |
| 113 | |
| 114 | if resumedTask.Status() == task.StatusSuspending { |
| 115 | q.metric.IncSuspendingTask() |
| 116 | q.metric.IncSubmittedTask() |
| 117 | } |
| 118 | |
| 119 | if err := q.QueueTask(ctx, resumedTask); err != nil { |
| 120 | q.logger.Warning("Failed to resume task %d: %s", t.ID, err) |
| 121 | } |
| 122 | resumed++ |
| 123 | } |
| 124 | |
| 125 | q.logger.Info("Resumed %d tasks from DB.", resumed) |
| 126 | } |
| 127 | |
| 128 | q.start() |
| 129 | }) |
| 130 | q.logger.Info("Queue %q started with %d workers.", q.name, q.workerCount) |
| 131 | } |
| 132 | |
| 133 | // Shutdown stops all queues. |
| 134 | func (q *queue) Shutdown() { |
nothing calls this directly
no test coverage detected