| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "container/heap" | 8 "container/heap" |
| 9 "errors" | 9 "errors" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 isPullQueue: isPullQueue, | 56 isPullQueue: isPullQueue, |
| 57 tasks: map[string]*tq.Task{}, | 57 tasks: map[string]*tq.Task{}, |
| 58 archived: map[string]*tq.Task{}, | 58 archived: map[string]*tq.Task{}, |
| 59 sortedPerTag: map[string]*taskIndex{}, | 59 sortedPerTag: map[string]*taskIndex{}, |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 // All sortedQueue methods are assumed to be called under taskQueueData lock. | 63 // All sortedQueue methods are assumed to be called under taskQueueData lock. |
| 64 | 64 |
| 65 func (q *sortedQueue) genTaskName(c context.Context) string { | 65 func (q *sortedQueue) genTaskName(c context.Context) string { |
| 66 const validTaskChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL
MNOPQRSTUVWXYZ-_" | |
| 67 for { | 66 for { |
| 68 » » buf := [500]byte{} | 67 » » // Real Task Queue service seems to be using random ints too. |
| 69 » » for i := 0; i < 500; i++ { | 68 » » name := fmt.Sprintf("%d", mathrand.Int63(c)) |
| 70 » » » buf[i] = validTaskChars[mathrand.Intn(c, len(validTaskCh
ars))] | |
| 71 » » } | |
| 72 » » name := string(buf[:]) | |
| 73 _, ok1 := q.tasks[name] | 69 _, ok1 := q.tasks[name] |
| 74 _, ok2 := q.archived[name] | 70 _, ok2 := q.archived[name] |
| 75 if !ok1 && !ok2 { | 71 if !ok1 && !ok2 { |
| 76 return name | 72 return name |
| 77 } | 73 } |
| 78 } | 74 } |
| 79 } | 75 } |
| 80 | 76 |
| 81 func (q *sortedQueue) addTask(task *tq.Task) error { | 77 func (q *sortedQueue) addTask(task *tq.Task) error { |
| 82 switch { | 78 switch { |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 return t.parent.GetScheduledTasks() | 526 return t.parent.GetScheduledTasks() |
| 531 } | 527 } |
| 532 | 528 |
| 533 func (t *txnTaskQueueData) CreateQueue(queueName string) { | 529 func (t *txnTaskQueueData) CreateQueue(queueName string) { |
| 534 t.parent.CreateQueue(queueName) | 530 t.parent.CreateQueue(queueName) |
| 535 } | 531 } |
| 536 | 532 |
| 537 func (t *txnTaskQueueData) CreatePullQueue(queueName string) { | 533 func (t *txnTaskQueueData) CreatePullQueue(queueName string) { |
| 538 t.parent.CreatePullQueue(queueName) | 534 t.parent.CreatePullQueue(queueName) |
| 539 } | 535 } |
| OLD | NEW |