Skip to content

Commit 4234ae5

Browse files
authored
An event now means the thing happened (#827)
1 parent df56002 commit 4234ae5

5 files changed

Lines changed: 252 additions & 125 deletions

File tree

quilt-sync/src-tauri/src/commands/package_ops.rs

Lines changed: 80 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ pub async fn package_commit(
5353
workflow: WorkflowIntent,
5454
uri: Option<S3PackageUri>,
5555
) -> Result<String, String> {
56-
tracing.track(MixpanelEvent::PackageCommitted(PackageEvent::for_uri(
57-
uri.as_ref(),
58-
)));
59-
6056
let msg_init = format!("Committing package {namespace}");
6157
let msg_ok = format!("Successfully committed {namespace}");
6258
let msg_err = |err: &Error| format!("Failed to commit: {err}");
@@ -65,7 +61,12 @@ pub async fn package_commit(
6561
if let Ok(ns) = &result {
6662
watcher.clear_paused(ns).await;
6763
}
68-
Notify::new(msg_init).map(result.map(|_| ()), msg_ok, msg_err)
64+
Notify::new(msg_init)
65+
.on_success(
66+
&tracing,
67+
MixpanelEvent::PackageCommitted(PackageEvent::for_uri(uri.as_ref())),
68+
)
69+
.map(result.map(|_| ()), msg_ok, msg_err)
6970
}
7071

7172
async fn certify_latest_command(m: &model::Model, namespace: &str) -> Result<(), Error> {
@@ -81,19 +82,20 @@ pub async fn certify_latest(
8182
namespace: String,
8283
uri: Option<S3PackageUri>,
8384
) -> Result<String, String> {
84-
tracing.track(MixpanelEvent::LatestCertified(RemotePackageEvent::for_uri(
85-
uri.as_ref(),
86-
)));
87-
8885
let msg_init = format!("Certifying latest for {namespace}");
8986
let msg_ok = format!("Successfully certified latest for {namespace}");
9087
let msg_err = |err: &Error| format!("Failed to certify latest: {err}");
9188

92-
Notify::new(msg_init).map(
93-
certify_latest_command(&m, &namespace).await,
94-
msg_ok,
95-
msg_err,
96-
)
89+
Notify::new(msg_init)
90+
.on_success(
91+
&tracing,
92+
MixpanelEvent::LatestCertified(RemotePackageEvent::for_uri(uri.as_ref())),
93+
)
94+
.map(
95+
certify_latest_command(&m, &namespace).await,
96+
msg_ok,
97+
msg_err,
98+
)
9799
}
98100

99101
async fn reset_local_command(
@@ -113,10 +115,6 @@ pub async fn reset_local(
113115
namespace: String,
114116
uri: Option<S3PackageUri>,
115117
) -> Result<String, String> {
116-
tracing.track(MixpanelEvent::LocalReset(RemotePackageEvent::for_uri(
117-
uri.as_ref(),
118-
)));
119-
120118
let msg_init = format!("Resetting local for {namespace}");
121119
let msg_ok = format!("Successfully reset local for {namespace}");
122120
let msg_err = |err: &Error| format!("Failed to reset local: {err}");
@@ -125,7 +123,12 @@ pub async fn reset_local(
125123
if let Ok(ns) = &result {
126124
watcher.clear_paused(ns).await;
127125
}
128-
Notify::new(msg_init).map(result.map(|_| ()), msg_ok, msg_err)
126+
Notify::new(msg_init)
127+
.on_success(
128+
&tracing,
129+
MixpanelEvent::LocalReset(RemotePackageEvent::for_uri(uri.as_ref())),
130+
)
131+
.map(result.map(|_| ()), msg_ok, msg_err)
129132
}
130133

131134
/// The user-visible text for a failed write, given the action that failed
@@ -163,10 +166,6 @@ pub async fn package_push(
163166
namespace: String,
164167
uri: Option<S3PackageUri>,
165168
) -> Result<String, String> {
166-
tracing.track(MixpanelEvent::PackagePushed(RemotePackageEvent::for_uri(
167-
uri.as_ref(),
168-
)));
169-
170169
let msg_init = format!("Pushing package {namespace}");
171170

172171
let result = package_push_command(&m, &namespace).await;
@@ -187,7 +186,12 @@ pub async fn package_push(
187186
};
188187
let msg_err = |err: &Error| write_failure_message("push package", err);
189188

190-
Notify::new(msg_init).map(result.map(|_| ()), msg_ok, msg_err)
189+
Notify::new(msg_init)
190+
.on_success(
191+
&tracing,
192+
MixpanelEvent::PackagePushed(RemotePackageEvent::for_uri(uri.as_ref())),
193+
)
194+
.map(result.map(|_| ()), msg_ok, msg_err)
191195
}
192196

193197
async fn package_publish_command(
@@ -352,10 +356,6 @@ pub async fn package_pull(
352356
namespace: String,
353357
uri: Option<S3PackageUri>,
354358
) -> Result<String, String> {
355-
tracing.track(MixpanelEvent::PackagePulled(RemotePackageEvent::for_uri(
356-
uri.as_ref(),
357-
)));
358-
359359
let msg_init = format!("Pulling package {namespace}");
360360
let msg_ok = format!("Successfully pulled package {namespace}");
361361
let msg_err = |err: &Error| format!("Failed to pull package: {err}");
@@ -364,7 +364,12 @@ pub async fn package_pull(
364364
if let Ok(ns) = &result {
365365
watcher.clear_paused(ns).await;
366366
}
367-
Notify::new(msg_init).map(result.map(|_| ()), msg_ok, msg_err)
367+
Notify::new(msg_init)
368+
.on_success(
369+
&tracing,
370+
MixpanelEvent::PackagePulled(RemotePackageEvent::for_uri(uri.as_ref())),
371+
)
372+
.map(result.map(|_| ()), msg_ok, msg_err)
368373
}
369374

370375
async fn package_pull_outcome_command(
@@ -407,19 +412,20 @@ pub async fn package_uninstall(
407412
namespace: String,
408413
uri: Option<S3PackageUri>,
409414
) -> Result<String, String> {
410-
tracing.track(MixpanelEvent::PackageUninstalled(PackageEvent::for_uri(
411-
uri.as_ref(),
412-
)));
413-
414415
let msg_init = format!("Uninstalling package {namespace}");
415416
let msg_ok = format!("Successfully uninstalled package {namespace}");
416417
let msg_err = |err: &Error| format!("Failed to uninstall package: {err}");
417418

418-
Notify::new(msg_init).map(
419-
package_uninstall_command(&m, &namespace).await,
420-
msg_ok,
421-
msg_err,
422-
)
419+
Notify::new(msg_init)
420+
.on_success(
421+
&tracing,
422+
MixpanelEvent::PackageUninstalled(PackageEvent::for_uri(uri.as_ref())),
423+
)
424+
.map(
425+
package_uninstall_command(&m, &namespace).await,
426+
msg_ok,
427+
msg_err,
428+
)
423429
}
424430

425431
/// Typed response for the `set_remote` command. `resolution_warning` is
@@ -459,15 +465,17 @@ pub async fn set_remote(
459465
) -> Result<SetRemoteResponse, String> {
460466
// The origin is this command's own argument: the remote being set.
461467
let origin_host = Host::from_str(&origin).ok();
462-
tracing.track(MixpanelEvent::RemoteSet(RemotePackageEvent::for_host(
463-
origin_host,
464-
)));
465-
466468
// `Notify::new` logs the init line; on success/failure we log explicitly so
467469
// the success payload can be the typed struct rather than a bare string.
468470
Notify::new(format!("Setting remote for {namespace}"));
469471
match set_remote_command(&m, &namespace, &origin, &bucket, workflow).await {
470472
Ok((ns, resolution_warning)) => {
473+
// Reported here rather than through `Notify::on_success`, because this
474+
// command returns a typed payload and so does not route its outcome
475+
// through `map`. Same rule, hand-applied: the success arm only.
476+
tracing.track(MixpanelEvent::RemoteSet(RemotePackageEvent::for_host(
477+
origin_host,
478+
)));
471479
watcher.clear_paused(&ns).await;
472480
let message = format!("Successfully set remote for {namespace}");
473481
::tracing::debug!("{message}");
@@ -505,17 +513,20 @@ pub async fn package_create(
505513
message: Option<String>,
506514
) -> Result<String, String> {
507515
// A package created here has no remote yet, so it belongs to no deployment.
508-
tracing.track(MixpanelEvent::PackageCreated(PackageEvent::hostless()));
509-
510516
let msg_init = format!("Creating package {namespace}");
511517
let msg_ok = format!("Successfully created package {namespace}");
512518
let msg_err = |err: &Error| format!("Failed to create package: {err}");
513519

514-
Notify::new(msg_init).map(
515-
package_create_command(&m, &namespace, source, message).await,
516-
msg_ok,
517-
msg_err,
518-
)
520+
Notify::new(msg_init)
521+
.on_success(
522+
&tracing,
523+
MixpanelEvent::PackageCreated(PackageEvent::hostless()),
524+
)
525+
.map(
526+
package_create_command(&m, &namespace, source, message).await,
527+
msg_ok,
528+
msg_err,
529+
)
519530
}
520531

521532
async fn package_install_paths_command(
@@ -538,19 +549,20 @@ pub async fn package_install_paths(
538549
) -> Result<String, String> {
539550
// Installing names its package by URI, so the catalog is already in hand.
540551
let target = S3PackageUri::try_from(uri.as_str()).ok();
541-
tracing.track(MixpanelEvent::PackageInstalled(
542-
RemotePackageEvent::for_uri(target.as_ref()),
543-
));
544-
545552
let msg_init = format!("Installing paths from {uri}");
546553
let msg_ok = format!("Successfully installed {} paths", paths.len());
547554
let msg_err = |err: &Error| format!("Failed to install paths: {err}");
548555

549-
Notify::new(msg_init).map(
550-
package_install_paths_command(&m, &uri, &paths).await,
551-
msg_ok,
552-
msg_err,
553-
)
556+
Notify::new(msg_init)
557+
.on_success(
558+
&tracing,
559+
MixpanelEvent::PackageInstalled(RemotePackageEvent::for_uri(target.as_ref())),
560+
)
561+
.map(
562+
package_install_paths_command(&m, &uri, &paths).await,
563+
msg_ok,
564+
msg_err,
565+
)
554566
}
555567

556568
async fn add_to_quiltignore_command(
@@ -591,19 +603,20 @@ pub async fn add_to_quiltignore(
591603
pattern: String,
592604
uri: Option<S3PackageUri>,
593605
) -> Result<String, String> {
594-
tracing.track(MixpanelEvent::QuiltignorePatternAdded(
595-
PackageEvent::for_uri(uri.as_ref()),
596-
));
597-
598606
let msg_init = format!("Adding {pattern} to .quiltignore");
599607
let msg_ok = format!("Added {pattern} to .quiltignore");
600608
let msg_err = |err: &Error| format!("Failed to update .quiltignore: {err}");
601609

602-
Notify::new(msg_init).map(
603-
add_to_quiltignore_command(&m, &namespace, &pattern).await,
604-
msg_ok,
605-
msg_err,
606-
)
610+
Notify::new(msg_init)
611+
.on_success(
612+
&tracing,
613+
MixpanelEvent::QuiltignorePatternAdded(PackageEvent::for_uri(uri.as_ref())),
614+
)
615+
.map(
616+
add_to_quiltignore_command(&m, &namespace, &pattern).await,
617+
msg_ok,
618+
msg_err,
619+
)
607620
}
608621

609622
#[tauri::command]

0 commit comments

Comments
 (0)