Files
Daniel Espino GarcíaandGitHub c197717461 [MM-69221] (#37301)
* [MM-69221]

* Address coderabbit comments

* Add tests to worker

* Address coderabbit comment
2026-07-13 17:45:37 +02:00

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)
}