@@ -21,6 +21,7 @@ import (
21
21
22
22
"go.coder.com/flog"
23
23
24
+ "cdr.dev/coder-cli/internal/activity"
24
25
"cdr.dev/coder-cli/internal/entclient"
25
26
"cdr.dev/wsep"
26
27
)
@@ -33,8 +34,11 @@ type Sync struct {
33
34
LocalDir string
34
35
// RemoteDir is an absolute path.
35
36
RemoteDir string
36
- entclient.Environment
37
- * entclient.Client
37
+ // DisableMetrics disables activity metric pushing.
38
+ DisableMetrics bool
39
+
40
+ Env entclient.Environment
41
+ Client * entclient.Client
38
42
}
39
43
40
44
func (s Sync ) syncPaths (delete bool , local , remote string ) error {
@@ -43,7 +47,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
43
47
args := []string {"-zz" ,
44
48
"-a" ,
45
49
"--delete" ,
46
- "-e" , self + " sh" , local , s .Environment .Name + ":" + remote ,
50
+ "-e" , self + " sh" , local , s .Env .Name + ":" + remote ,
47
51
}
48
52
if delete {
49
53
args = append ([]string {"--delete" }, args ... )
@@ -68,7 +72,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
68
72
}
69
73
70
74
func (s Sync ) remoteRm (ctx context.Context , remote string ) error {
71
- conn , err := s .Client .DialWsep (ctx , s .Environment )
75
+ conn , err := s .Client .DialWsep (ctx , s .Env )
72
76
if err != nil {
73
77
return err
74
78
}
@@ -229,13 +233,16 @@ func (s Sync) workEventGroup(evs []timedEvent) {
229
233
}
230
234
231
235
const (
232
- // maxinflightInotify sets the maximum number of inotifies before the sync just restarts.
233
- // Syncing a large amount of small files (e.g .git or node_modules) is impossible to do performantly
234
- // with individual rsyncs.
236
+ // maxinflightInotify sets the maximum number of inotifies before the
237
+ // sync just restarts. Syncing a large amount of small files (e.g .git
238
+ // or node_modules) is impossible to do performantly with individual
239
+ // rsyncs.
235
240
maxInflightInotify = 8
236
241
maxEventDelay = time .Second * 7
237
- // maxAcceptableDispatch is the maximum amount of time before an event should begin its journey to the server.
238
- // This sets a lower bound for perceivable latency, but the higher it is, the better the optimization.
242
+ // maxAcceptableDispatch is the maximum amount of time before an event
243
+ // should begin its journey to the server. This sets a lower bound for
244
+ // perceivable latency, but the higher it is, the better the
245
+ // optimization.
239
246
maxAcceptableDispatch = time .Millisecond * 50
240
247
)
241
248
@@ -245,13 +252,17 @@ const (
245
252
func (s Sync ) Run () error {
246
253
events := make (chan notify.EventInfo , maxInflightInotify )
247
254
// Set up a recursive watch.
248
- // We do this before the initial sync so we can capture any changes that may have happened during sync.
255
+ // We do this before the initial sync so we can capture any changes
256
+ // that may have happened during sync.
249
257
err := notify .Watch (path .Join (s .LocalDir , "..." ), events , notify .All )
250
258
if err != nil {
251
259
return xerrors .Errorf ("create watch: %w" , err )
252
260
}
253
261
defer notify .Stop (events )
254
262
263
+ ap := activity .NewPusher (s .Client , s .Env .ID , activityName )
264
+ ap .Push ()
265
+
255
266
setConsoleTitle ("⏳ syncing project" )
256
267
err = s .initSync ()
257
268
if err != nil {
@@ -265,7 +276,8 @@ func (s Sync) Run() error {
265
276
flog .Info ("watching %s for changes" , s .LocalDir )
266
277
267
278
var droppedEvents uint64
268
- // Timed events lets us track how long each individual file takes to update.
279
+ // Timed events lets us track how long each individual file takes to
280
+ // update.
269
281
timedEvents := make (chan timedEvent , cap (events ))
270
282
go func () {
271
283
defer close (timedEvents )
@@ -309,6 +321,9 @@ func (s Sync) Run() error {
309
321
}
310
322
s .workEventGroup (eventGroup )
311
323
eventGroup = eventGroup [:0 ]
324
+ ap .Push ()
312
325
}
313
326
}
314
327
}
328
+
329
+ const activityName = "sync"
0 commit comments