2019-02-09 12:30:49 +00:00
|
|
|
package api
|
|
|
|
|
2019-02-11 22:44:13 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
2019-11-07 04:35:04 +00:00
|
|
|
|
|
|
|
"github.com/stashapp/stash/pkg/manager"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2019-02-11 22:44:13 +00:00
|
|
|
)
|
2019-02-09 12:30:49 +00:00
|
|
|
|
2019-11-07 04:35:04 +00:00
|
|
|
func (r *subscriptionResolver) MetadataUpdate(ctx context.Context) (<-chan *models.MetadataUpdateStatus, error) {
|
|
|
|
msg := make(chan *models.MetadataUpdateStatus, 1)
|
2019-02-11 22:44:13 +00:00
|
|
|
|
|
|
|
ticker := time.NewTicker(5 * time.Second)
|
|
|
|
|
|
|
|
go func() {
|
2019-11-07 04:35:04 +00:00
|
|
|
lastStatus := manager.TaskStatus{}
|
2019-02-11 22:44:13 +00:00
|
|
|
for {
|
|
|
|
select {
|
2019-02-14 22:53:32 +00:00
|
|
|
case _ = <-ticker.C:
|
2019-11-07 04:35:04 +00:00
|
|
|
thisStatus := manager.GetInstance().Status
|
|
|
|
if thisStatus != lastStatus {
|
|
|
|
ret := models.MetadataUpdateStatus{
|
|
|
|
Progress: thisStatus.Progress,
|
|
|
|
Status: thisStatus.Status.String(),
|
|
|
|
Message: "",
|
|
|
|
}
|
|
|
|
msg <- &ret
|
|
|
|
}
|
|
|
|
lastStatus = thisStatus
|
2019-02-11 22:44:13 +00:00
|
|
|
case <-ctx.Done():
|
|
|
|
ticker.Stop()
|
|
|
|
close(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return msg, nil
|
2019-02-14 22:53:32 +00:00
|
|
|
}
|