mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* [MM-69221] * Address coderabbit comments * Add tests to worker * Address coderabbit comment
41 lines
998 B
Go
41 lines
998 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package docextractor
|
|
|
|
import (
|
|
"runtime"
|
|
"sync"
|
|
)
|
|
|
|
// maxConcurrentExtractions caps how many docconv extractions may run at once,
|
|
// including detached goroutines that continue after a per-extraction timeout.
|
|
var maxConcurrentExtractions = runtime.NumCPU()
|
|
|
|
var (
|
|
extractionSlotsMu sync.Mutex
|
|
extractionSlots = make(chan struct{}, maxConcurrentExtractions)
|
|
)
|
|
|
|
func tryAcquireExtractionSlot() bool {
|
|
select {
|
|
case extractionSlots <- struct{}{}:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func releaseExtractionSlot() {
|
|
<-extractionSlots
|
|
}
|
|
|
|
// resetExtractionConcurrencyForTest reinitializes the extraction slot semaphore.
|
|
// It is only intended for use from tests in this package.
|
|
func resetExtractionConcurrencyForTest(limit int) {
|
|
extractionSlotsMu.Lock()
|
|
defer extractionSlotsMu.Unlock()
|
|
maxConcurrentExtractions = limit
|
|
extractionSlots = make(chan struct{}, limit)
|
|
}
|