Mercurial > gemma
comparison pkg/imports/queue.go @ 5601:1222b777f51f
Made golint finally happy.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 06 Aug 2022 02:09:57 +0200 |
parents | aaa9e658cabd |
children | 2dd155cc95ec |
comparison
equal
deleted
inserted
replaced
5600:9967a78e43f4 | 5601:1222b777f51f |
---|---|
65 // CleanUp is called to clean up ressources hold by the import. | 65 // CleanUp is called to clean up ressources hold by the import. |
66 // It is called whether the import succeeded or not. | 66 // It is called whether the import succeeded or not. |
67 CleanUp() error | 67 CleanUp() error |
68 } | 68 } |
69 | 69 |
70 // FeedbackJob is a job to create feedback. | |
70 FeedbackJob interface { | 71 FeedbackJob interface { |
71 Job | 72 Job |
72 CreateFeedback(int64) Feedback | 73 CreateFeedback(int64) Feedback |
73 } | 74 } |
74 | 75 |
96 // AutoAccept indicates that imports of this kind | 97 // AutoAccept indicates that imports of this kind |
97 // don't need a review. | 98 // don't need a review. |
98 AutoAccept() bool | 99 AutoAccept() bool |
99 } | 100 } |
100 | 101 |
102 // JobRemover is a extented JobCreator to remove a job. | |
101 JobRemover interface { | 103 JobRemover interface { |
102 JobCreator | 104 JobCreator |
103 RemoveJob() bool | 105 RemoveJob() bool |
104 } | 106 } |
105 | 107 |
118 pollDuration = time.Second * 10 | 120 pollDuration = time.Second * 10 |
119 runExclusive = -66666 | 121 runExclusive = -66666 |
120 ) | 122 ) |
121 | 123 |
122 const ( | 124 const ( |
125 // ReviewJobSuffix is the prefix of review jobs. | |
123 ReviewJobSuffix = "#review" | 126 ReviewJobSuffix = "#review" |
124 reviewJobRetries = 200 | 127 reviewJobRetries = 200 |
125 reviewJobWait = 10 * time.Minute | 128 reviewJobWait = 10 * time.Minute |
126 ) | 129 ) |
127 | 130 |
128 const ( | 131 const ( |
129 hardMaxTries = 200 | 132 hardMaxTries = 200 |
130 minWaitRetry = 5 * time.Second | 133 minWaitRetry = 5 * time.Second |
131 ) | 134 ) |
132 | 135 |
136 // ErrRetrying are used to signal a retry. | |
133 var ErrRetrying = errors.New("retrying") | 137 var ErrRetrying = errors.New("retrying") |
134 | 138 |
135 type importQueue struct { | 139 type importQueue struct { |
136 cmdCh chan func(*importQueue) | 140 cmdCh chan func(*importQueue) |
137 | 141 |
280 return new(reviewedJob) | 284 return new(reviewedJob) |
281 } | 285 } |
282 | 286 |
283 func (*reviewedJob) CleanUp() error { return nil } | 287 func (*reviewedJob) CleanUp() error { return nil } |
284 | 288 |
285 func (r *reviewedJob) CreateFeedback(int64) Feedback { | 289 func (rj *reviewedJob) CreateFeedback(int64) Feedback { |
286 return logFeedback(r.ID) | 290 return logFeedback(rj.ID) |
287 } | 291 } |
288 | 292 |
289 func (rj *reviewedJob) Do( | 293 func (rj *reviewedJob) Do( |
290 ctx context.Context, | 294 ctx context.Context, |
291 importID int64, | 295 importID int64, |
388 // HasImportKindName checks if the import queue supports a given kind. | 392 // HasImportKindName checks if the import queue supports a given kind. |
389 func HasImportKindName(kind string) bool { | 393 func HasImportKindName(kind string) bool { |
390 return iqueue.hasImportKindName(kind) | 394 return iqueue.hasImportKindName(kind) |
391 } | 395 } |
392 | 396 |
393 // | |
394 func (q *importQueue) hasImportKindName(kind string) bool { | 397 func (q *importQueue) hasImportKindName(kind string) bool { |
395 q.creatorsMu.Lock() | 398 q.creatorsMu.Lock() |
396 defer q.creatorsMu.Unlock() | 399 defer q.creatorsMu.Unlock() |
397 return q.creators[JobKind(kind)] != nil | 400 return q.creators[JobKind(kind)] != nil |
398 } | 401 } |
720 return ErrRetrying | 723 return ErrRetrying |
721 } | 724 } |
722 return nil | 725 return nil |
723 } | 726 } |
724 | 727 |
728 // DecideImport decides if a given import is accepted or not. | |
725 func DecideImport( | 729 func DecideImport( |
726 ctx context.Context, | 730 ctx context.Context, |
727 id int64, | 731 id int64, |
728 accepted bool, | 732 accepted bool, |
729 reviewer string, | 733 reviewer string, |
737 for k, v := range q.creators { | 741 for k, v := range q.creators { |
738 fn(k, v) | 742 fn(k, v) |
739 } | 743 } |
740 } | 744 } |
741 | 745 |
746 // All reports all configured job creators and there kind | |
747 // to the given function. | |
742 func All(fn func(JobKind, JobCreator)) { iqueue.All(fn) } | 748 func All(fn func(JobKind, JobCreator)) { iqueue.All(fn) } |
743 | 749 |
744 type logFeedback int64 | 750 type logFeedback int64 |
745 | 751 |
746 func (lf logFeedback) log(kind, format string, args ...interface{}) { | 752 func (lf logFeedback) log(kind, format string, args ...interface{}) { |