Throttle queue notifications
This commit is contained in:
parent
23461ee707
commit
66a4288ec9
|
@ -5,10 +5,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/viktorstrate/photoview/api/graphql/models"
|
"github.com/viktorstrate/photoview/api/graphql/models"
|
||||||
"github.com/viktorstrate/photoview/api/graphql/notification"
|
"github.com/viktorstrate/photoview/api/graphql/notification"
|
||||||
|
"github.com/viktorstrate/photoview/api/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScannerJob struct {
|
type ScannerJob struct {
|
||||||
|
@ -48,6 +50,9 @@ func InitializeScannerQueue(db *sql.DB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (queue *ScannerQueue) startBackgroundWorker() {
|
func (queue *ScannerQueue) startBackgroundWorker() {
|
||||||
|
|
||||||
|
notifyThrottle := utils.NewThrottle(500 * time.Millisecond)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
log.Println("Queue waiting")
|
log.Println("Queue waiting")
|
||||||
<-queue.idle_chan
|
<-queue.idle_chan
|
||||||
|
@ -95,11 +100,13 @@ func (queue *ScannerQueue) startBackgroundWorker() {
|
||||||
Positive: true,
|
Positive: true,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
notification.BroadcastNotification(&models.Notification{
|
notifyThrottle.Trigger(func() {
|
||||||
Key: "global-scanner-progress",
|
notification.BroadcastNotification(&models.Notification{
|
||||||
Type: models.NotificationTypeMessage,
|
Key: "global-scanner-progress",
|
||||||
Header: fmt.Sprintf("Scanning photos"),
|
Type: models.NotificationTypeMessage,
|
||||||
Content: fmt.Sprintf("%d jobs in progress\n%d jobs waiting", in_progress_length, up_next_length),
|
Header: fmt.Sprintf("Scanning photos"),
|
||||||
|
Content: fmt.Sprintf("%d jobs in progress\n%d jobs waiting", in_progress_length, up_next_length),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue