2023-06-12 15:13:57 +02:00
package command
import (
2023-08-10 11:42:37 +02:00
"context"
2023-06-12 15:13:57 +02:00
"github.com/cs3org/reva/v2/pkg/events"
2023-08-07 14:05:57 +02:00
"github.com/cs3org/reva/v2/pkg/events/stream"
2023-06-12 15:13:57 +02:00
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser"
"github.com/urfave/cli/v2"
)
// RestartPostprocessing cli command to restart postprocessing
func RestartPostprocessing ( cfg * config . Config ) * cli . Command {
return & cli . Command {
Name : "restart" ,
Usage : "restart postprocessing for an uploadID" ,
Flags : [] cli . Flag {
& cli . StringFlag {
2024-01-25 12:08:00 +01:00
Name : "upload-id" ,
Aliases : [] string { "u" },
Usage : "the uploadid to restart. 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.
2023-06-12 15:13:57 +02:00
},
},
Before : func ( c * cli . Context ) error {
return configlog . ReturnFatal ( parser . ParseConfig ( cfg ))
},
Action : func ( c * cli . Context ) error {
2023-12-18 11:47:25 +01:00
stream , err := stream . NatsFromConfig ( cfg . Service . Name , false , stream . NatsConfig ( cfg . Postprocessing . Events ))
2023-06-12 15:13:57 +02:00
if err != nil {
return err
}
2024-01-25 12:08:00 +01:00
uid , step := c . String ( "upload-id" ), ""
if uid == "" {
step = c . String ( "step" )
2023-06-12 15:13:57 +02:00
}
2024-01-25 12:08:00 +01:00
ev := events . ResumePostprocessing {
UploadID : uid ,
Step : events . Postprocessingstep ( step ),
Timestamp : utils . TSNow (),
2023-06-12 15:13:57 +02:00
}
2024-01-25 12:08:00 +01:00
return events . Publish ( context . Background (), stream , ev )
2023-06-12 15:13:57 +02:00
},
}
}