mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 20:49:02 +00:00
Throttle queue notifications
This commit is contained in:
@@ -5,10 +5,12 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/viktorstrate/photoview/api/graphql/models"
|
||||
"github.com/viktorstrate/photoview/api/graphql/notification"
|
||||
"github.com/viktorstrate/photoview/api/utils"
|
||||
)
|
||||
|
||||
type ScannerJob struct {
|
||||
@@ -48,6 +50,9 @@ func InitializeScannerQueue(db *sql.DB) {
|
||||
}
|
||||
|
||||
func (queue *ScannerQueue) startBackgroundWorker() {
|
||||
|
||||
notifyThrottle := utils.NewThrottle(500 * time.Millisecond)
|
||||
|
||||
for {
|
||||
log.Println("Queue waiting")
|
||||
<-queue.idle_chan
|
||||
@@ -95,11 +100,13 @@ func (queue *ScannerQueue) startBackgroundWorker() {
|
||||
Positive: true,
|
||||
})
|
||||
} else {
|
||||
notification.BroadcastNotification(&models.Notification{
|
||||
Key: "global-scanner-progress",
|
||||
Type: models.NotificationTypeMessage,
|
||||
Header: fmt.Sprintf("Scanning photos"),
|
||||
Content: fmt.Sprintf("%d jobs in progress\n%d jobs waiting", in_progress_length, up_next_length),
|
||||
notifyThrottle.Trigger(func() {
|
||||
notification.BroadcastNotification(&models.Notification{
|
||||
Key: "global-scanner-progress",
|
||||
Type: models.NotificationTypeMessage,
|
||||
Header: fmt.Sprintf("Scanning photos"),
|
||||
Content: fmt.Sprintf("%d jobs in progress\n%d jobs waiting", in_progress_length, up_next_length),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user