mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 16:34:02 +01:00
Stop tasks and show task progress (#181)
* Add job status to tasks page * Add support for stopping task * Show progress of some tasks
This commit is contained in:
parent
d1ea2fffa5
commit
c0911f1626
13 changed files with 283 additions and 68 deletions
|
|
@ -16,4 +16,16 @@ query MetadataGenerate($input: GenerateMetadataInput!) {
|
||||||
|
|
||||||
query MetadataClean {
|
query MetadataClean {
|
||||||
metadataClean
|
metadataClean
|
||||||
|
}
|
||||||
|
|
||||||
|
query JobStatus {
|
||||||
|
jobStatus {
|
||||||
|
progress
|
||||||
|
status
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query StopJob {
|
||||||
|
stopJob
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
subscription MetadataUpdate {
|
subscription MetadataUpdate {
|
||||||
metadataUpdate
|
metadataUpdate {
|
||||||
|
progress
|
||||||
|
status
|
||||||
|
message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subscription LoggingSubscribe {
|
subscription LoggingSubscribe {
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,9 @@ type Query {
|
||||||
"""Clean metadata. Returns the job ID"""
|
"""Clean metadata. Returns the job ID"""
|
||||||
metadataClean: String!
|
metadataClean: String!
|
||||||
|
|
||||||
|
jobStatus: MetadataUpdateStatus!
|
||||||
|
stopJob: Boolean!
|
||||||
|
|
||||||
# Get everything
|
# Get everything
|
||||||
|
|
||||||
allPerformers: [Performer!]!
|
allPerformers: [Performer!]!
|
||||||
|
|
@ -106,7 +109,7 @@ type Mutation {
|
||||||
|
|
||||||
type Subscription {
|
type Subscription {
|
||||||
"""Update from the metadata manager"""
|
"""Update from the metadata manager"""
|
||||||
metadataUpdate: String!
|
metadataUpdate: MetadataUpdateStatus!
|
||||||
|
|
||||||
loggingSubscribe: [LogEntry!]!
|
loggingSubscribe: [LogEntry!]!
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,10 @@ input GenerateMetadataInput {
|
||||||
|
|
||||||
input ScanMetadataInput {
|
input ScanMetadataInput {
|
||||||
nameFromMetadata: Boolean!
|
nameFromMetadata: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
|
type MetadataUpdateStatus {
|
||||||
|
progress: Float!
|
||||||
|
status: String!
|
||||||
|
message: String!
|
||||||
}
|
}
|
||||||
|
|
@ -31,3 +31,18 @@ func (r *queryResolver) MetadataClean(ctx context.Context) (string, error) {
|
||||||
manager.GetInstance().Clean()
|
manager.GetInstance().Clean()
|
||||||
return "todo", nil
|
return "todo", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *queryResolver) JobStatus(ctx context.Context) (*models.MetadataUpdateStatus, error) {
|
||||||
|
status := manager.GetInstance().Status
|
||||||
|
ret := models.MetadataUpdateStatus{
|
||||||
|
Progress: status.Progress,
|
||||||
|
Status: status.Status.String(),
|
||||||
|
Message: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *queryResolver) StopJob(ctx context.Context) (bool, error) {
|
||||||
|
return manager.GetInstance().Status.Stop(), nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,32 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/stashapp/stash/pkg/manager"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stashapp/stash/pkg/manager"
|
||||||
|
"github.com/stashapp/stash/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *subscriptionResolver) MetadataUpdate(ctx context.Context) (<-chan string, error) {
|
func (r *subscriptionResolver) MetadataUpdate(ctx context.Context) (<-chan *models.MetadataUpdateStatus, error) {
|
||||||
msg := make(chan string, 1)
|
msg := make(chan *models.MetadataUpdateStatus, 1)
|
||||||
|
|
||||||
ticker := time.NewTicker(5 * time.Second)
|
ticker := time.NewTicker(5 * time.Second)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
lastStatus := manager.TaskStatus{}
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case _ = <-ticker.C:
|
case _ = <-ticker.C:
|
||||||
manager.GetInstance().HandleMetadataUpdateSubscriptionTick(msg)
|
thisStatus := manager.GetInstance().Status
|
||||||
|
if thisStatus != lastStatus {
|
||||||
|
ret := models.MetadataUpdateStatus{
|
||||||
|
Progress: thisStatus.Progress,
|
||||||
|
Status: thisStatus.Status.String(),
|
||||||
|
Message: "",
|
||||||
|
}
|
||||||
|
msg <- &ret
|
||||||
|
}
|
||||||
|
lastStatus = thisStatus
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
close(msg)
|
close(msg)
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,22 @@ const (
|
||||||
Clean JobStatus = 5
|
Clean JobStatus = 5
|
||||||
Scrape JobStatus = 6
|
Scrape JobStatus = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s JobStatus) String() string {
|
||||||
|
statusMessage := ""
|
||||||
|
|
||||||
|
switch s {
|
||||||
|
case Idle:
|
||||||
|
statusMessage = "Idle"
|
||||||
|
case Import:
|
||||||
|
statusMessage = "Import"
|
||||||
|
case Export:
|
||||||
|
statusMessage = "Export"
|
||||||
|
case Scan:
|
||||||
|
statusMessage = "Scan"
|
||||||
|
case Generate:
|
||||||
|
statusMessage = "Generate"
|
||||||
|
}
|
||||||
|
|
||||||
|
return statusMessage
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type singleton struct {
|
type singleton struct {
|
||||||
Status JobStatus
|
Status TaskStatus
|
||||||
Paths *paths.Paths
|
Paths *paths.Paths
|
||||||
JSON *jsonUtils
|
JSON *jsonUtils
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ func Initialize() *singleton {
|
||||||
initFlags()
|
initFlags()
|
||||||
initEnvs()
|
initEnvs()
|
||||||
instance = &singleton{
|
instance = &singleton{
|
||||||
Status: Idle,
|
Status: TaskStatus{Status: Idle, Progress: -1},
|
||||||
Paths: paths.NewPaths(),
|
Paths: paths.NewPaths(),
|
||||||
JSON: &jsonUtils{},
|
JSON: &jsonUtils{},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
package manager
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/stashapp/stash/pkg/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
type metadataUpdatePayload struct {
|
|
||||||
Progress float64 `json:"progress"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
Logs []logger.LogItem `json:"logs"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *singleton) HandleMetadataUpdateSubscriptionTick(msg chan string) {
|
|
||||||
var statusMessage string
|
|
||||||
switch instance.Status {
|
|
||||||
case Idle:
|
|
||||||
statusMessage = "Idle"
|
|
||||||
case Import:
|
|
||||||
statusMessage = "Import"
|
|
||||||
case Export:
|
|
||||||
statusMessage = "Export"
|
|
||||||
case Scan:
|
|
||||||
statusMessage = "Scan"
|
|
||||||
case Generate:
|
|
||||||
statusMessage = "Generate"
|
|
||||||
}
|
|
||||||
payload := &metadataUpdatePayload{
|
|
||||||
Progress: 0, // TODO
|
|
||||||
Message: statusMessage,
|
|
||||||
Logs: logger.LogCache,
|
|
||||||
}
|
|
||||||
payloadJSON, _ := json.Marshal(payload)
|
|
||||||
|
|
||||||
msg <- string(payloadJSON)
|
|
||||||
}
|
|
||||||
|
|
@ -3,6 +3,7 @@ package manager
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bmatcuk/doublestar"
|
"github.com/bmatcuk/doublestar"
|
||||||
"github.com/stashapp/stash/pkg/logger"
|
"github.com/stashapp/stash/pkg/logger"
|
||||||
|
|
@ -11,11 +12,47 @@ import (
|
||||||
"github.com/stashapp/stash/pkg/utils"
|
"github.com/stashapp/stash/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TaskStatus struct {
|
||||||
|
Status JobStatus
|
||||||
|
Progress float64
|
||||||
|
LastUpdate time.Time
|
||||||
|
stopping bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskStatus) Stop() bool {
|
||||||
|
t.stopping = true
|
||||||
|
t.updated()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskStatus) SetStatus(s JobStatus) {
|
||||||
|
t.Status = s
|
||||||
|
t.updated()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskStatus) setProgress(upTo int, total int) {
|
||||||
|
if total == 0 {
|
||||||
|
t.Progress = 1
|
||||||
|
}
|
||||||
|
t.Progress = float64(upTo) / float64(total)
|
||||||
|
t.updated()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskStatus) indefiniteProgress() {
|
||||||
|
t.Progress = -1
|
||||||
|
t.updated()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskStatus) updated() {
|
||||||
|
t.LastUpdate = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
func (s *singleton) Scan(nameFromMetadata bool) {
|
func (s *singleton) Scan(nameFromMetadata bool) {
|
||||||
if s.Status != Idle {
|
if s.Status.Status != Idle {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Status = Scan
|
s.Status.SetStatus(Scan)
|
||||||
|
s.Status.indefiniteProgress()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer s.returnToIdleState()
|
defer s.returnToIdleState()
|
||||||
|
|
@ -26,10 +63,23 @@ func (s *singleton) Scan(nameFromMetadata bool) {
|
||||||
globResults, _ := doublestar.Glob(globPath)
|
globResults, _ := doublestar.Glob(globPath)
|
||||||
results = append(results, globResults...)
|
results = append(results, globResults...)
|
||||||
}
|
}
|
||||||
logger.Infof("Starting scan of %d files", len(results))
|
|
||||||
|
if s.Status.stopping {
|
||||||
|
logger.Info("Stopping due to user request")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
total := len(results)
|
||||||
|
logger.Infof("Starting scan of %d files", total)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, path := range results {
|
s.Status.Progress = 0
|
||||||
|
for i, path := range results {
|
||||||
|
s.Status.setProgress(i, total)
|
||||||
|
if s.Status.stopping {
|
||||||
|
logger.Info("Stopping due to user request")
|
||||||
|
return
|
||||||
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
task := ScanTask{FilePath: path, NameFromMetadata: nameFromMetadata}
|
task := ScanTask{FilePath: path, NameFromMetadata: nameFromMetadata}
|
||||||
go task.Start(&wg)
|
go task.Start(&wg)
|
||||||
|
|
@ -41,10 +91,11 @@ func (s *singleton) Scan(nameFromMetadata bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleton) Import() {
|
func (s *singleton) Import() {
|
||||||
if s.Status != Idle {
|
if s.Status.Status != Idle {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Status = Import
|
s.Status.SetStatus(Import)
|
||||||
|
s.Status.indefiniteProgress()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer s.returnToIdleState()
|
defer s.returnToIdleState()
|
||||||
|
|
@ -58,10 +109,11 @@ func (s *singleton) Import() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleton) Export() {
|
func (s *singleton) Export() {
|
||||||
if s.Status != Idle {
|
if s.Status.Status != Idle {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Status = Export
|
s.Status.SetStatus(Export)
|
||||||
|
s.Status.indefiniteProgress()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer s.returnToIdleState()
|
defer s.returnToIdleState()
|
||||||
|
|
@ -75,10 +127,11 @@ func (s *singleton) Export() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcodes bool) {
|
func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcodes bool) {
|
||||||
if s.Status != Idle {
|
if s.Status.Status != Idle {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Status = Generate
|
s.Status.SetStatus(Generate)
|
||||||
|
s.Status.indefiniteProgress()
|
||||||
|
|
||||||
qb := models.NewSceneQueryBuilder()
|
qb := models.NewSceneQueryBuilder()
|
||||||
//this.job.total = await ObjectionUtils.getCount(Scene);
|
//this.job.total = await ObjectionUtils.getCount(Scene);
|
||||||
|
|
@ -95,7 +148,21 @@ func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcod
|
||||||
|
|
||||||
delta := utils.Btoi(sprites) + utils.Btoi(previews) + utils.Btoi(markers) + utils.Btoi(transcodes)
|
delta := utils.Btoi(sprites) + utils.Btoi(previews) + utils.Btoi(markers) + utils.Btoi(transcodes)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, scene := range scenes {
|
s.Status.Progress = 0
|
||||||
|
total := len(scenes)
|
||||||
|
|
||||||
|
if s.Status.stopping {
|
||||||
|
logger.Info("Stopping due to user request")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, scene := range scenes {
|
||||||
|
s.Status.setProgress(i, total)
|
||||||
|
if s.Status.stopping {
|
||||||
|
logger.Info("Stopping due to user request")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if scene == nil {
|
if scene == nil {
|
||||||
logger.Errorf("nil scene, skipping generate")
|
logger.Errorf("nil scene, skipping generate")
|
||||||
continue
|
continue
|
||||||
|
|
@ -134,10 +201,11 @@ func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcod
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleton) Clean() {
|
func (s *singleton) Clean() {
|
||||||
if s.Status != Idle {
|
if s.Status.Status != Idle {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Status = Clean
|
s.Status.SetStatus(Clean)
|
||||||
|
s.Status.indefiniteProgress()
|
||||||
|
|
||||||
qb := models.NewSceneQueryBuilder()
|
qb := models.NewSceneQueryBuilder()
|
||||||
go func() {
|
go func() {
|
||||||
|
|
@ -150,8 +218,21 @@ func (s *singleton) Clean() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.Status.stopping {
|
||||||
|
logger.Info("Stopping due to user request")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, scene := range scenes {
|
s.Status.Progress = 0
|
||||||
|
total := len(scenes)
|
||||||
|
for i, scene := range scenes {
|
||||||
|
s.Status.setProgress(i, total)
|
||||||
|
if s.Status.stopping {
|
||||||
|
logger.Info("Stopping due to user request")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if scene == nil {
|
if scene == nil {
|
||||||
logger.Errorf("nil scene, skipping generate")
|
logger.Errorf("nil scene, skipping generate")
|
||||||
continue
|
continue
|
||||||
|
|
@ -173,8 +254,10 @@ func (s *singleton) returnToIdleState() {
|
||||||
logger.Info("recovered from ", r)
|
logger.Info("recovered from ", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Status == Generate {
|
if s.Status.Status == Generate {
|
||||||
instance.Paths.Generated.RemoveTmpDir()
|
instance.Paths.Generated.RemoveTmpDir()
|
||||||
}
|
}
|
||||||
s.Status = Idle
|
s.Status.SetStatus(Idle)
|
||||||
|
s.Status.indefiniteProgress()
|
||||||
|
s.Status.stopping = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
package manager
|
package manager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stashapp/stash/pkg/ffmpeg"
|
|
||||||
"github.com/stashapp/stash/pkg/logger"
|
|
||||||
"github.com/stashapp/stash/pkg/models"
|
|
||||||
"github.com/stashapp/stash/pkg/utils"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/stashapp/stash/pkg/ffmpeg"
|
||||||
|
"github.com/stashapp/stash/pkg/logger"
|
||||||
|
"github.com/stashapp/stash/pkg/models"
|
||||||
|
"github.com/stashapp/stash/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenerateMarkersTask struct {
|
type GenerateMarkersTask struct {
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,10 @@ import {
|
||||||
FormGroup,
|
FormGroup,
|
||||||
H4,
|
H4,
|
||||||
AnchorButton,
|
AnchorButton,
|
||||||
|
ProgressBar,
|
||||||
|
H5,
|
||||||
} from "@blueprintjs/core";
|
} from "@blueprintjs/core";
|
||||||
import React, { FunctionComponent, useState } from "react";
|
import React, { FunctionComponent, useState, useEffect } from "react";
|
||||||
import { StashService } from "../../../core/StashService";
|
import { StashService } from "../../../core/StashService";
|
||||||
import { ErrorUtils } from "../../../utils/errors";
|
import { ErrorUtils } from "../../../utils/errors";
|
||||||
import { ToastUtils } from "../../../utils/toasts";
|
import { ToastUtils } from "../../../utils/toasts";
|
||||||
|
|
@ -20,10 +22,58 @@ export const SettingsTasksPanel: FunctionComponent<IProps> = (props: IProps) =>
|
||||||
const [isImportAlertOpen, setIsImportAlertOpen] = useState<boolean>(false);
|
const [isImportAlertOpen, setIsImportAlertOpen] = useState<boolean>(false);
|
||||||
const [isCleanAlertOpen, setIsCleanAlertOpen] = useState<boolean>(false);
|
const [isCleanAlertOpen, setIsCleanAlertOpen] = useState<boolean>(false);
|
||||||
const [nameFromMetadata, setNameFromMetadata] = useState<boolean>(true);
|
const [nameFromMetadata, setNameFromMetadata] = useState<boolean>(true);
|
||||||
|
const [status, setStatus] = useState<string>("");
|
||||||
|
const [progress, setProgress] = useState<number | undefined>(undefined);
|
||||||
|
|
||||||
|
const jobStatus = StashService.useJobStatus();
|
||||||
|
const metadataUpdate = StashService.useMetadataUpdate();
|
||||||
|
|
||||||
|
function statusToText(status : string) {
|
||||||
|
switch(status) {
|
||||||
|
case "Idle":
|
||||||
|
return "Idle";
|
||||||
|
case "Scan":
|
||||||
|
return "Scanning for new content";
|
||||||
|
case "Generate":
|
||||||
|
return "Generating supporting files";
|
||||||
|
case "Clean":
|
||||||
|
return "Cleaning the database";
|
||||||
|
case "Export":
|
||||||
|
return "Exporting to JSON";
|
||||||
|
case "Import":
|
||||||
|
return "Importing from JSON";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Idle";
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!!jobStatus.data && !!jobStatus.data.jobStatus) {
|
||||||
|
setStatus(statusToText(jobStatus.data.jobStatus.status));
|
||||||
|
var newProgress = jobStatus.data.jobStatus.progress;
|
||||||
|
if (newProgress < 0) {
|
||||||
|
setProgress(undefined);
|
||||||
|
} else {
|
||||||
|
setProgress(newProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [jobStatus.data]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!!metadataUpdate.data && !!metadataUpdate.data.metadataUpdate) {
|
||||||
|
setStatus(statusToText(metadataUpdate.data.metadataUpdate.status));
|
||||||
|
var newProgress = metadataUpdate.data.metadataUpdate.progress;
|
||||||
|
if (newProgress < 0) {
|
||||||
|
setProgress(undefined);
|
||||||
|
} else {
|
||||||
|
setProgress(newProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [metadataUpdate.data]);
|
||||||
|
|
||||||
function onImport() {
|
function onImport() {
|
||||||
setIsImportAlertOpen(false);
|
setIsImportAlertOpen(false);
|
||||||
StashService.queryMetadataImport();
|
StashService.queryMetadataImport().then(() => { jobStatus.refetch()});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderImportAlert() {
|
function renderImportAlert() {
|
||||||
|
|
@ -47,7 +97,7 @@ export const SettingsTasksPanel: FunctionComponent<IProps> = (props: IProps) =>
|
||||||
|
|
||||||
function onClean() {
|
function onClean() {
|
||||||
setIsCleanAlertOpen(false);
|
setIsCleanAlertOpen(false);
|
||||||
StashService.queryMetadataClean();
|
StashService.queryMetadataClean().then(() => { jobStatus.refetch()});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderCleanAlert() {
|
function renderCleanAlert() {
|
||||||
|
|
@ -74,16 +124,49 @@ export const SettingsTasksPanel: FunctionComponent<IProps> = (props: IProps) =>
|
||||||
try {
|
try {
|
||||||
await StashService.queryMetadataScan({nameFromMetadata});
|
await StashService.queryMetadataScan({nameFromMetadata});
|
||||||
ToastUtils.success("Started scan");
|
ToastUtils.success("Started scan");
|
||||||
|
jobStatus.refetch();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ErrorUtils.handle(e);
|
ErrorUtils.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeRenderStop() {
|
||||||
|
if (!status || status === "Idle") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FormGroup>
|
||||||
|
<Button id="stop" text="Stop" intent="danger" onClick={() => StashService.queryStopJob().then(() => jobStatus.refetch())} />
|
||||||
|
</FormGroup>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderJobStatus() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FormGroup>
|
||||||
|
<H5>Status: {status}</H5>
|
||||||
|
{!!status && status !== "Idle" ? <ProgressBar value={progress}/> : undefined}
|
||||||
|
</FormGroup>
|
||||||
|
{maybeRenderStop()}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{renderImportAlert()}
|
{renderImportAlert()}
|
||||||
{renderCleanAlert()}
|
{renderCleanAlert()}
|
||||||
|
|
||||||
|
<H4>Running Jobs</H4>
|
||||||
|
|
||||||
|
{renderJobStatus()}
|
||||||
|
|
||||||
|
<Divider/>
|
||||||
|
|
||||||
<H4>Library</H4>
|
<H4>Library</H4>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
helperText="Scan for new content and add it to the database."
|
helperText="Scan for new content and add it to the database."
|
||||||
|
|
@ -122,7 +205,7 @@ export const SettingsTasksPanel: FunctionComponent<IProps> = (props: IProps) =>
|
||||||
labelFor="export"
|
labelFor="export"
|
||||||
inline={true}
|
inline={true}
|
||||||
>
|
>
|
||||||
<Button id="export" text="Export" onClick={() => StashService.queryMetadataExport()} />
|
<Button id="export" text="Export" onClick={() => StashService.queryMetadataExport().then(() => { jobStatus.refetch()})} />
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
<FormGroup
|
<FormGroup
|
||||||
|
|
|
||||||
|
|
@ -346,6 +346,19 @@ export class StashService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static useJobStatus() {
|
||||||
|
return GQL.useJobStatus({
|
||||||
|
fetchPolicy: 'no-cache'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static queryStopJob() {
|
||||||
|
return StashService.client.query<GQL.StopJobQuery>({
|
||||||
|
query: GQL.StopJobDocument,
|
||||||
|
fetchPolicy: "network-only",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static queryScrapeFreeones(performerName: string) {
|
public static queryScrapeFreeones(performerName: string) {
|
||||||
return StashService.client.query<GQL.ScrapeFreeonesQuery>({
|
return StashService.client.query<GQL.ScrapeFreeonesQuery>({
|
||||||
query: GQL.ScrapeFreeonesDocument,
|
query: GQL.ScrapeFreeonesDocument,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue