-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathp2p_document_sync.go
More file actions
61 lines (50 loc) · 2.09 KB
/
Copy pathp2p_document_sync.go
File metadata and controls
61 lines (50 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2025 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package cli
import (
"context"
"github.com/spf13/cobra"
"github.com/sourcenetwork/defradb/client/options"
iIdentity "github.com/sourcenetwork/defradb/internal/identity"
)
func MakeP2PDocumentSyncCommand(ctx context.Context) *cobra.Command {
var cmd = &cobra.Command{
Use: "sync <collection-name> <docID...>",
Short: "Synchronize specific documents from the network",
Long: `Synchronize specific documents from the network.
This command allows you to sync documents from a specific collection across the network.
It doesn't automatically subscribe to the collection or the documents.`,
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
collectionName := args[0]
docIDs := args[1:]
ctx := cmd.Context()
if timeout, _ := cmd.Flags().GetDuration("timeout"); timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
}
cliClient := mustGetContextCLIClient(cmd)
opt := options.WithIdentity(options.SyncDocuments(), iIdentity.FromContext(cmd.Context()))
if blockSyncTimeout, _ := cmd.Flags().GetDuration("block-sync-timeout"); blockSyncTimeout > 0 {
opt = opt.SetBlockSyncTimeout(blockSyncTimeout)
}
return cliClient.SyncDocuments(ctx, collectionName, docIDs, opt)
},
}
EmbedCLIExample(ctx, cmd, "sync single document",
`defradb client p2p document sync Users bae123`)
EmbedCLIExample(ctx, cmd, "sync multiple documents",
`defradb client p2p document sync Users bae123 bae456`)
cmd.Flags().Duration("timeout", 0, "Timeout for the whole sync operation")
cmd.Flags().Duration("block-sync-timeout", 0,
"Per-block fetch timeout for this sync, overriding the node default (e.g. 30s)")
return cmd
}