Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: impl/memory/taskqueue_data.go

Issue 2547793002: impl/memory: Use random int as auto generated task name in Task Queues. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | impl/memory/taskqueue_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | impl/memory/taskqueue_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698