mirror of
https://github.com/rclone/rclone.git
synced 2025-08-18 09:30:03 +02:00
accounting: isolate stats to groups
Introduce stats groups that will isolate accounting for logically different transferring operations. That way multiple accounting operations can be done in parallel without interfering with each other stats. Using groups is optional. There is dedicated global stats that will be used by default if no group is specified. This is operating mode for CLI usage which is just fire and forget operation. For running rclone as rc http server each request will create it's own group. Also there is an option to specify your own group.
This commit is contained in:
committed by
Nick Craig-Wood
parent
be0464f5f1
commit
8243ff8bc8
@@ -3,6 +3,8 @@ package rcserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -10,6 +12,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
|
||||
"github.com/ncw/rclone/fs/rc/jobs"
|
||||
|
||||
"github.com/ncw/rclone/cmd/serve/httplib"
|
||||
"github.com/ncw/rclone/cmd/serve/httplib/serve"
|
||||
"github.com/ncw/rclone/fs"
|
||||
@@ -18,7 +24,6 @@ import (
|
||||
"github.com/ncw/rclone/fs/list"
|
||||
"github.com/ncw/rclone/fs/rc"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
)
|
||||
|
||||
// Start the remote control server if configured
|
||||
@@ -79,7 +84,10 @@ func (s *Server) Serve() error {
|
||||
if user != "" || pass != "" {
|
||||
openURL.User = url.UserPassword(user, pass)
|
||||
}
|
||||
_ = open.Start(openURL.String())
|
||||
// Don't open browser if serving in testing environment.
|
||||
if flag.Lookup("test.v") == nil {
|
||||
_ = open.Start(openURL.String())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -181,15 +189,16 @@ func (s *Server) handlePost(w http.ResponseWriter, r *http.Request, path string)
|
||||
writeError(path, in, w, err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
delete(in, "_async") // remove the async parameter after parsing so vfs operations don't get confused
|
||||
|
||||
fs.Debugf(nil, "rc: %q: with parameters %+v", path, in)
|
||||
var out rc.Params
|
||||
if isAsync {
|
||||
out, err = rc.StartJob(call.Fn, in)
|
||||
out, err = jobs.StartAsyncJob(call.Fn, in)
|
||||
} else {
|
||||
out, err = call.Fn(r.Context(), in)
|
||||
var jobID int64
|
||||
out, jobID, err = jobs.ExecuteJob(r.Context(), call.Fn, in)
|
||||
w.Header().Add("x-rclone-jobid", fmt.Sprintf("%d", jobID))
|
||||
}
|
||||
if err != nil {
|
||||
writeError(path, in, w, err, http.StatusInternalServerError)
|
||||
|
Reference in New Issue
Block a user