()
| 309 | } |
| 310 | |
| 311 | func (t *TaskQueue) read() { |
| 312 | |
| 313 | taskQueueRead, err := t.center.TaskQueueRead() |
| 314 | if err != nil { |
| 315 | t.log.Errorln("read task queue TaskQueueRead error:", err) |
| 316 | return |
| 317 | } |
| 318 | |
| 319 | for i := 0; i <= taskPriorityCount; i++ { |
| 320 | |
| 321 | value, bok := taskQueueRead[i] |
| 322 | if bok == false { |
| 323 | continue |
| 324 | } |
| 325 | err = t.taskPriorityMapList[i].FromJSON(value) |
| 326 | if err != nil { |
| 327 | t.log.Errorln("read task queue FromJSON error:", err) |
| 328 | } |
| 329 | // 上面的操作仅仅是把 OneJob 的 JSON 弄了出来,还需要转换为 OneJob 的结构体 |
| 330 | // JobID - OneJob |
| 331 | t.taskPriorityMapList[i].Each(func(key interface{}, value interface{}) { |
| 332 | |
| 333 | jsonString, err := json.Marshal(value) |
| 334 | if err != nil { |
| 335 | t.log.Panicln(err) |
| 336 | } |
| 337 | nowOneJob := task_queue2.OneJob{} |
| 338 | err = json.Unmarshal(jsonString, &nowOneJob) |
| 339 | if err != nil { |
| 340 | t.log.Panicln(err) |
| 341 | } |
| 342 | t.taskPriorityMapList[i].Put(key, nowOneJob) |
| 343 | }) |
| 344 | // 需要把几个优先级的map中的key汇总 |
| 345 | // JobID - OneJob |
| 346 | t.taskPriorityMapList[i].Each(func(key interface{}, value interface{}) { |
| 347 | // JobID -- taskPriority |
| 348 | t.taskKeyMap.Put(key, i) |
| 349 | // SeriesRootDirPath -- tree.Set(JobID) |
| 350 | oneJob := value.(task_queue2.OneJob) |
| 351 | jobIDSet, found := t.taskGroupBySeries.Get(oneJob.SeriesRootDirPath) |
| 352 | if found == false { |
| 353 | // 不存在 |
| 354 | nowJobIDSet := treeset.NewWithStringComparator() |
| 355 | nowJobIDSet.Add(oneJob.Id) |
| 356 | t.taskGroupBySeries.Put(oneJob.SeriesRootDirPath, nowJobIDSet) |
| 357 | } else { |
| 358 | // 存在 |
| 359 | nowJobIDSet := jobIDSet.(*treeset.Set) |
| 360 | nowJobIDSet.Add(oneJob.Id) |
| 361 | t.taskGroupBySeries.Put(oneJob.SeriesRootDirPath, nowJobIDSet) |
| 362 | } |
| 363 | }) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func (t *TaskQueue) afterRead() { |
| 368 | // 将 downloading 的任务重置为 waiting |
no test coverage detected