Skip to content

Commit

Permalink
Merge pull request #10439 from kobergj/RestartPPReworked
Browse files Browse the repository at this point in the history
Restart Postprocessing Properly
  • Loading branch information
kobergj authored Nov 4, 2024
2 parents a2b9868 + 64ff815 commit e85a8b9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/restart-postprocessing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Restart Postprocessing properly

Properly differentiate between resume and restart postprocessing.

https://github.com/owncloud/ocis/pull/10439
2 changes: 2 additions & 0 deletions services/postprocessing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ ocis postprocessing restart # Restarts all uploads where postproc
ocis postprocessing restart -s "finished" # Equivalent to the above
ocis postprocessing restart -s "virusscan" # Restart all uploads currently in virusscan step
```
Note: All above commands containing the word `restart` can also be replaced by `resume`. This changes behaviour slightly. When `restarting` an upload, the whole postprocessing will be (re)done. If `resuming` an upload, it will only continue from the last step that was completed.
33 changes: 24 additions & 9 deletions services/postprocessing/pkg/command/postprocessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@ import (
// RestartPostprocessing cli command to restart postprocessing
func RestartPostprocessing(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "restart",
Usage: "restart postprocessing for an uploadID",
Name: "resume",
Aliases: []string{"restart"},
Usage: "resume postprocessing for an uploadID",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "upload-id",
Aliases: []string{"u"},
Usage: "the uploadid to restart. Ignored if unset.",
Usage: "the uploadid to resume. Ignored if unset.",
},
&cli.StringFlag{
Name: "step",
Aliases: []string{"s"},
Usage: "restarts all uploads in the given postprocessing step. Ignored if upload-id is set.",
Value: "finished", // Calling `ocis postprocessing restart` without any arguments will restart all uploads that are finished but failed to move the uploed from the upload area to the blobstore.
Usage: "resume all uploads in the given postprocessing step. Ignored if upload-id is set.",
Value: "finished",
},
&cli.BoolFlag{
Name: "restart",
Aliases: []string{"r"},
Usage: "restart postprocessing for the given uploadID. Ignores the step flag.",
},
},
Before: func(c *cli.Context) error {
Expand All @@ -44,10 +50,19 @@ func RestartPostprocessing(cfg *config.Config) *cli.Command {
step = c.String("step")
}

ev := events.ResumePostprocessing{
UploadID: uid,
Step: events.Postprocessingstep(step),
Timestamp: utils.TSNow(),
var ev events.Unmarshaller
switch {
case c.Bool("retrigger"):
ev = events.RestartPostprocessing{
UploadID: uid,
Timestamp: utils.TSNow(),
}
default:
ev = events.ResumePostprocessing{
UploadID: uid,
Step: events.Postprocessingstep(step),
Timestamp: utils.TSNow(),
}
}

return events.Publish(context.Background(), stream, ev)
Expand Down
26 changes: 20 additions & 6 deletions services/storage-users/pkg/command/uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ func ListUploadSessions(cfg *config.Config) *cli.Command {
},
&cli.BoolFlag{
Name: "restart",
Usage: "send restart event for all listed sessions",
Usage: "send restart event for all listed sessions. Only one of resume/restart/clean can be set.",
},
&cli.BoolFlag{
Name: "resume",
Usage: "send resume event for all listed sessions. Only one of resume/restart/clean can be set.",
},
&cli.BoolFlag{
Name: "clean",
Usage: "remove uploads",
Usage: "remove uploads for all listed sessions. Only one of resume/restart/clean can be set.",
},
},
Before: func(c *cli.Context) error {
Expand Down Expand Up @@ -176,18 +180,28 @@ func ListUploadSessions(cfg *config.Config) *cli.Command {
})
}

if c.Bool("restart") {
if err := events.Publish(context.Background(), stream, events.ResumePostprocessing{
switch {
case c.Bool("restart"):
if err := events.Publish(context.Background(), stream, events.RestartPostprocessing{
UploadID: u.ID(),
Timestamp: utils.TSNow(),
}); err != nil {
fmt.Fprintf(os.Stderr, "Failed to send restart event for upload session '%s'\n", u.ID())
// if publishing fails there is no need to try publishing other events - they will fail too.
os.Exit(1)
}
}

if c.Bool("clean") {
case c.Bool("resume"):
if err := events.Publish(context.Background(), stream, events.ResumePostprocessing{
UploadID: u.ID(),
Timestamp: utils.TSNow(),
}); err != nil {
fmt.Fprintf(os.Stderr, "Failed to send resume event for upload session '%s'\n", u.ID())
// if publishing fails there is no need to try publishing other events - they will fail too.
os.Exit(1)
}

case c.Bool("clean"):
if err := u.Purge(c.Context); err != nil {
fmt.Fprintf(os.Stderr, "Failed to clean upload session '%s'\n", u.ID())
}
Expand Down

0 comments on commit e85a8b9

Please sign in to comment.