Skip to content

Commit

Permalink
allow restarting multiple uploads at once
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Apr 8, 2024
1 parent 622d1bb commit 1c78a4c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions services/storage-users/pkg/command/uploads.go
@@ -1,6 +1,7 @@
package command

import (
"context"
"encoding/json"
"fmt"
"os"
Expand All @@ -13,11 +14,14 @@ import (
"github.com/urfave/cli/v2"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/storage"
"github.com/cs3org/reva/v2/pkg/storage/fs/registry"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config"
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config/parser"
"github.com/owncloud/ocis/v2/services/storage-users/pkg/event"
"github.com/owncloud/ocis/v2/services/storage-users/pkg/revaconfig"
)

Expand Down Expand Up @@ -101,6 +105,10 @@ func ListUploadSessions(cfg *config.Config) *cli.Command {
Name: "json",
Usage: "output as json",
},
&cli.BoolFlag{
Name: "restart",
Usage: "send restart event for all listed sessions",
},
},
Before: func(c *cli.Context) error {
return configlog.ReturnFatal(parser.ParseConfig(cfg))
Expand All @@ -124,6 +132,15 @@ func ListUploadSessions(cfg *config.Config) *cli.Command {
os.Exit(1)
}

var stream events.Stream
if c.Bool("restart") {
stream, err = event.NewStream(cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create event stream: %v\n", err)
os.Exit(1)
}
}

var b strings.Builder
filter := storage.UploadSessionFilter{}
if c.IsSet("processing") {
Expand Down Expand Up @@ -200,6 +217,16 @@ func ListUploadSessions(cfg *config.Config) *cli.Command {
fmt.Println(err)
}
fmt.Println(string(j))

if c.Bool("restart") {
if err := events.Publish(context.Background(), stream, events.ResumePostprocessing{
UploadID: u.ID(),
Timestamp: utils.TSNow(),
}); err != nil {
fmt.Fprintf(os.Stderr, "Failed to send restart event for upload session '%s'\n", u.ID())
os.Exit(1)
}
}
}
} else {

Expand All @@ -223,6 +250,16 @@ func ListUploadSessions(cfg *config.Config) *cli.Command {
u.Expires().Format(time.RFC3339),
strconv.FormatBool(u.IsProcessing()),
})

if c.Bool("restart") {
if err := events.Publish(context.Background(), stream, events.ResumePostprocessing{
UploadID: u.ID(),
Timestamp: utils.TSNow(),
}); err != nil {
fmt.Fprintf(os.Stderr, "Failed to send restart event for upload session '%s'\n", u.ID())
os.Exit(1)
}
}
}
table.Render()
}
Expand Down

0 comments on commit 1c78a4c

Please sign in to comment.